#include <bits/stdc++.h>
using namespace std;
const int maxn = 5003;
int a[maxn];
map<int, int> mini, maxi;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int b;
    cin >> a[i] >> b;
    if (mini[a[i]] == 0)
      mini[a[i]] = b;
    else
      mini[a[i]] = min(mini[a[i]], b);
    if (maxi[a[i]] == 0)
      maxi[a[i]] = b;
    else
      maxi[a[i]] = max(maxi[a[i]], b);
  }
  sort(a + 1, a + n + 1);
  int prev = 0;
  for (int i = 1; i <= n; i++)
    if (a[i] != a[i - 1]) {
      if (mini[a[i]] >= prev)
        prev = maxi[a[i]];
      else
        prev = a[i];
    }
  cout << prev << "\n";
  cin >> n;
  return 0;
}
