typedef struct line { long long int start; long long int ends; } line;
int cmp(line a,line b) { if(a.start<b.start||(a.start==b.start&&a.ends>b.ends)) return true; else return false; }
int main() { int n; cin>>n; line all[50005]; for(int i=0; i<n; i++) { cin>>all[i].start>>all[i].ends; } long long int chongdie=0; // insert_sort(all,n); sort(all,all+n,cmp); long long int chongdie2=0;
line m=all[0]; for(int i=1;i<n;i++) { chongdie=max(chongdie,min(all[i].ends,m.ends)-all[i].start); if(all[i].ends>m.ends) m=all[i]; }