#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = 1 << 29;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n >> b) & 1; }
inline void set_bit(int& n, int b) { n |= two(b); }
inline void unset_bit(int& n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) {
  int res = 0;
  while (n && ++res) n -= n & (-n);
  return res;
}
template <class T>
void chmax(T& a, const T& b) {
  a = max(a, b);
}
template <class T>
void chmin(T& a, const T& b) {
  a = min(a, b);
}
int l[300010], r[300010];
map<int, int> lfreq, rfreq;
int getLength() {
  return max(rfreq.begin()->first - (--lfreq.end())->first, 0);
}
void add(int i) {
  if (lfreq.find(l[i]) == lfreq.end()) {
    lfreq[l[i]] = 1;
  } else
    lfreq[l[i]] += 1;
  if (rfreq.find(r[i]) == rfreq.end()) {
    rfreq[r[i]] = 1;
  } else
    rfreq[r[i]] += 1;
}
void remove(int i) {
  lfreq[l[i]]--;
  rfreq[r[i]]--;
  if (lfreq[l[i]] == 0) {
    lfreq.erase(l[i]);
  }
  if (rfreq[r[i]] == 0) {
    rfreq.erase(r[i]);
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < (n); i++) {
    cin >> l[i] >> r[i];
    add(i);
  }
  int ans = 0;
  for (int i = 0; i < (n); i++) {
    remove(i);
    ans = max(ans, getLength());
    add(i);
  }
  cout << ans << "\n";
  return 0;
}
