#include <bits/stdc++.h>
const double PI = acos(-1);
const double EPS = 1e-10;
const int inf = 1e8;
using namespace std;
int main() {
  int n;
  cin >> n;
  int m = 100010;
  vector<int> in(m, 0);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    in[a]++;
    in[b + 1]--;
  }
  int ma = -1;
  int co = 0;
  for (int i = 0; i < 10; i++) {
    co += in[i];
    if (i - 1 <= co) ma = max(ma, i - 1);
  }
  cout << ma << endl;
}
