#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> v(100010, 0);
  for (int i = 0; i < (int)(N); ++i) {
    int a, b;
    cin >> a >> b;
    v[a]++;
    v[b + 1]--;
  }
  for (int i = (int)(1); i < (int)(v.size()); ++i) v[i] += v[i - 1];
  int ans = 1;
  for (int i = 0; i < (int)(v.size()); ++i)
    if (i <= v[i]) ans = max(ans, v[i]);
  cout << ans - 1 << endl;
  return 0;
}
