#include <bits/stdc++.h>
const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
using namespace std;
long long max(long long a, int b) { return max(a, long long(b)); }
long long max(int a, long long b) { return max(long long(a), b); }
long long min(long long a, int b) { return min(a, long long(b)); }
long long min(int a, long long b) { return min(long long(a), b); }
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> v(100003);
  int n;
  cin >> n;
  for (long long i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    v[b]--;
    v[a - 1]++;
  }
  int ans = 0;
  for (long long i = 0; i < v.size() - 1; ++i) v[i + 1] += v[i];
  for (long long i = 0; i < v.size(); ++i) {
    if (i + 1 == v[i]) ans = i + 1;
  }
  cout << max(0, ans - 1) << endl;
  return 0;
}
