#include <bits/stdc++.h>
using namespace std;
int n, lastdate = 0;
pair<int, int> a[5050];
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int(i) = 0; (i) < (n); (i)++) cin >> a[i].first >> a[i].second;
  sort(a, a + n);
  for (int(i) = 0; (i) < (n); (i)++)
    lastdate = (a[i].second >= lastdate) ? a[i].second : a[i].first;
  cout << lastdate << "\n";
  return 0;
}
