#include <bits/stdc++.h>
using namespace std;
class comp {
 public:
  bool operator()(pair<long long int, long long int>& first,
                  pair<long long int, long long int>& second) {
    if (first.first == second.first) return first.second < second.second;
    return first.first < second.first;
  }
};
pair<long long int, long long int> intersect(
    const pair<long long int, long long int>& a,
    const pair<long long int, long long int>& b) {
  return make_pair((a.first > b.first ? a.first : b.first),
                   (a.second < b.second ? a.second : b.second));
}
long long int longestInt(
    vector<pair<long long int, long long int> >& intervals) {
  sort(intervals.begin(), intervals.end(), comp());
  int n = intervals.size();
  vector<pair<long long int, long long int> > prefix(n), suffix(n);
  prefix[0] = intervals[0];
  suffix[n - 1] = intervals[n - 1];
  for (int i = 1; i < n; i++)
    prefix[i] = intersect(intervals[i], prefix[i - 1]);
  for (int i = n - 2; i >= 0; i--)
    suffix[i] = intersect(intervals[i], suffix[i + 1]);
  long long int maxLength = (prefix[n - 2].second - prefix[n - 2].first >
                                     suffix[1].second - suffix[1].first
                                 ? prefix[n - 2].second - prefix[n - 2].first
                                 : suffix[1].second - suffix[1].first);
  for (int i = 1; i <= n - 2; i++) {
    pair<long long int, long long int> firstHalf = prefix[i - 1],
                                       secondHalf = suffix[i + 1];
    pair<long long int, long long int> intersection =
        intersect(firstHalf, secondHalf);
    maxLength = (maxLength > intersection.second - intersection.first
                     ? maxLength
                     : intersection.second - intersection.first);
  }
  return (maxLength > 0 ? maxLength : 0);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<pair<long long int, long long int> > intervals(n);
  for (int i = 0; i < n; i++) cin >> intervals[i].first >> intervals[i].second;
  cout << longestInt(intervals) << endl;
  return 0;
}
