#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int OK[n][2];
  for (int i = 0; i < n; i++) cin >> OK[i][0] >> OK[i][1];
  int result[n + 2];
  for (int i = 0; i < n + 2; i++) result[i] = 0;
  for (int i = 1; i <= n + 1; i++) {
    for (int j = 0; j < n; j++) {
      if (OK[j][0] <= i && i <= OK[j][1]) result[i]++;
    }
  }
  for (int i = 0; i < n + 2; i++) {
    if (i <= result[i])
      result[i] = i - 1;
    else if (i - 1 > result[i])
      result[i] = -1;
  }
  int max = 0;
  for (int i = 0; i < n + 2; i++) {
    if (result[i] > max) max = result[i];
  }
  cout << max << endl;
  return 0;
}
