#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n;
  ;
  cin >> n;
  long long d[100010] = {0};
  for (long long i = 0; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    d[a - 1]++;
    d[b]--;
  }
  long long MAX = 0;
  for (long long i = 1; i < 100010; i++) {
    d[i] += d[i - 1];
    if (i == d[i] - 1) MAX = max(MAX, d[i] - 1);
  }
  cout << MAX << endl;
}
