#include <bits/stdc++.h>
const int MAXN = 300000;
const int INF = 0x3f3f3f3f;
using namespace std;
inline void enableFileIO() {
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
}
inline int read() {
  int x = 0, w = 1;
  char c = ' ';
  while (c < '0' || c > '9') {
    c = getchar();
    if (c == '-') w = -1;
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  return x * w;
}
struct Node {
  int x, y;
} a[MAXN + 5];
int n;
multiset<int> LS, RS;
void init() {
  n = read();
  for (int i = 1; i <= n; ++i) {
    a[i].x = read();
    a[i].y = read();
    LS.insert(a[i].x);
    RS.insert(a[i].y);
  }
}
int mx, mn, ans;
int main() {
  init();
  for (int i = 1; i <= n; ++i) {
    LS.erase(LS.find(a[i].x));
    RS.erase(RS.find(a[i].y));
    ans = max(ans, *RS.begin() - *(--LS.end()));
    LS.insert(a[i].x);
    RS.insert(a[i].y);
  }
  printf("%d\n", ans);
}
