#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int a[100000], b[100000];
  cin >> n;
  int max = 0, min = 100001;
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
    if (a[i] < min)
      min = a[i];
    else if (b[i] > max)
      max = b[i];
  }
  int max_friends = 1;
  for (int i = min; i < max; ++i) {
    int friends = 0;
    for (int j = 0; j < n; ++j) {
      if (a[j] <= i - 1 && b[j] >= i - 1) {
        ++friends;
      }
    }
    if (friends == i - 1 && --friends > max_friends) {
      max_friends = friends;
    }
  }
  cout << max_friends << endl;
  return 0;
}
