#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b;
  map<int, int> m;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    m[a]++;
    m[b]--;
  }
  map<int, int>::iterator it = m.begin(), jt;
  int cnt = 1;
  int ret = -1;
  while (it != m.end()) {
    cnt += (*it).second;
    jt = it;
    jt++;
    if (jt == m.end() || (*it).first <= cnt && cnt <= (*jt).first) {
      ret = max(ret, cnt);
    }
    ++it;
  }
  cout << ret - 1 << endl;
}
