#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    int n;
    cin >> n;
    int left = -1e9;
    int right = 1e9;
    priority_queue<pair<int, int>> leftcheck;
    priority_queue<pair<int, int>, vector<pair<int, int>>,
                   greater<pair<int, int>>>
        rightcheck;
    for (int i = 0; i < n; i++) {
      int a, b;
      cin >> a >> b;
      leftcheck.push(make_pair(a, i));
      rightcheck.push(make_pair(b, i));
    }
    int ans = 0;
    if ((leftcheck.top().second) == (rightcheck.top().second)) {
      leftcheck.pop();
      rightcheck.pop();
      ans = max(ans, (rightcheck.top()).first - (leftcheck.top().first));
    } else {
      int temp1, temp2, temp3, temp4;
      temp1 = (rightcheck.top()).first;
      temp2 = (leftcheck.top()).first;
      rightcheck.pop();
      leftcheck.pop();
      temp3 = (rightcheck.top()).first;
      temp4 = (leftcheck.top()).first;
      ans = max(ans, max(temp1 - temp4, temp3 - temp2));
    }
    cout << ans << endl;
  }
  return 0;
}
