#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     long long int a[n][2];     for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1];     long long int l[n][2], r[n][2];     long long int mi = a[0][0];     long long int mx = a[0][1];     l[0][0] = mi;     l[0][1] = mx;     if (n == 1) {       cout << a[0][1] - a[0][0];       return 0;     }     for (int i = 1; i < n; i++) {       if (l[i - 1][0] == -1) {         l[i][0] = -1;         l[i][1] = -1;         continue;       }       long long int x, y;       x = max(a[i][0], l[i - 1][0]);       y = min(a[i][1], l[i - 1][1]);       if (y - x < 0) {         l[i][0] = -1;         l[i][1] = -1;       } else {         l[i][0] = x;         l[i][1] = y;       }     }     mx = a[n - 1][1];     mi = a[n - 1][0];     r[n - 1][0] = mi;     r[n - 1][1] = mx;     for (int i = n - 2; i >= 0; i--) {       if (r[i + 1][0] == -1) {         r[i][0] = -1;         r[i][1] = -1;         continue;       }       long long int x, y;       x = max(a[i][0], r[i + 1][0]);       y = min(a[i][1], r[i + 1][1]);       if (y - x < 0) {         r[i][0] = -1;         r[i][1] = -1;       } else {         r[i][0] = x;         r[i][1] = y;       }     }     long long int ans = 0;     if (l[n - 2][0] != -1) ans = l[n - 2][1] - l[n - 2][0];     if (r[1][0] != -1) ans = max(ans, r[1][1] - r[1][0]);     for (int i = 1; i < n - 1; i++) {       long long int x, y;       if (l[i - 1][0] == -1 || r[i + 1][0] == -1) continue;       x = max(l[i - 1][0], r[i + 1][0]);       y = min(l[i - 1][1], r[i + 1][1]);       ans = max(ans, max((long long int)0, y - x));     }     cout << ans;   }   