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