#include <bits/stdc++.h>
using namespace std;
using ld = long double;
using ull = unsigned long long;
using ll = long long;
const ll N = 10010;
const double EPS = 1e-6;
const ll mod = 1000000000 + 7;
struct ListNode {
  int val;
  ListNode* next;
  ListNode(int x) : val(x), next(NULL) {}
};
ListNode* reverseList(ListNode* head) {
  if (!head->next) {
    return head;
  }
  head = reverseList(head->next);
  head->next = head;
}
void insert(int val, ListNode** node) {
  (*node)->next = new ListNode(val);
  *node = (*node)->next;
}
int main() {
  ios::sync_with_stdio(false);
  multiset<int, greater<int>> l;
  multiset<int> r;
  int n;
  cin >> n;
  vector<pair<int, int>> p(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i].first >> p[i].second;
    l.insert(p[i].first);
    r.insert(p[i].second);
  }
  ll ans = 0LL;
  for (int i = 0; i < n; ++i) {
    auto it = l.lower_bound(p[i].first);
    l.erase(it);
    it = r.lower_bound(p[i].second);
    r.erase(it);
    ans = max(ans, (ll)(*r.begin() - *l.begin()));
    l.insert(p[i].first);
    r.insert(p[i].second);
  }
  cout << ans << endl;
}
