#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  int a[100001], b[100001];
  for (int i = 0; i < ((int)(N)); i++) cin >> a[i] >> b[i];
  sort(a, a + N);
  sort(b, b + N);
  int current = 0, max = 0;
  int acnt = 0, bcnt = 0;
  int begin = -1;
  while (1) {
    if (acnt <= N - 1) {
      if (a[acnt] < b[bcnt]) {
        current++;
        begin = a[acnt];
        if (current + 1 >= begin) {
          if (current + 1 > b[bcnt]) {
            if (b[bcnt] - 1 > max) max = b[bcnt] - 1;
          } else {
            if (current > max) max = current;
          }
        }
        acnt++;
      } else if (a[acnt] > b[bcnt]) {
        current--;
        if (current + 1 >= begin) {
          if (current + 1 > b[bcnt]) {
            if (b[bcnt] - 1 > max) max = b[bcnt] - 1;
          } else {
            if (current > max) max = current;
          }
        }
        bcnt++;
      } else {
        current++;
        acnt++;
        if (current + 1 >= begin) {
          if (current + 1 > b[bcnt]) {
            if (b[bcnt] - 1 > max) max = b[bcnt] - 1;
          } else {
            if (current > max) max = current;
          }
        }
        bcnt++;
        current--;
        if (current + 1 >= begin) {
          if (current + 1 > b[bcnt]) {
            if (b[bcnt] - 1 > max) max = b[bcnt] - 1;
          } else {
            if (current > max) max = current;
          }
        }
      }
    } else {
      current--;
      if (current + 1 >= begin) {
        if (current + 1 > b[bcnt]) {
          if (b[bcnt] - 1 > max) max = b[bcnt] - 1;
        } else {
          if (current > max) max = current;
        }
      }
      bcnt++;
    }
    if (acnt == N && bcnt == N) break;
  }
  cout << max << endl;
  return 0;
}
