1 #include <bits/stdc++.h>
2 #define _xx ios_base::sync_with_stdio(0);cin.tie(0);
3 using namespace std;
4 typedef long long ll;
5 struct node
6 {
7 int s, e;
8 } a[50005];
9 bool operator < (const node& t1, const node& t2)
10 {
11 return t1.s < t2.s;
12 }
13 int main()
14 {_xx
15 int n, ans = 0;
16 cin >> n;
17 for(int i = 1; i <= n; i++) cin >> a[i].s >> a[i].e;
18 sort(a + 1, a + n + 1);
19 int lmost = 0;
20 for(int i = 1; i <= n; i++)
21 {
22 if(lmost <= a[i].e) ans = max(ans, lmost - a[i].s);
23 else ans = max(ans, a[i].e - a[i].s);
24 lmost = max(lmost, a[i].e);
25 }
26 cout << ans << endl;
27 return 0;
28 }