#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[5005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << setprecision(30);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first >> a[i].second;
  }
  sort(a + 1, a + n + 1);
  int pre = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i].second >= pre)
      pre = a[i].second;
    else
      pre = a[i].first;
  }
  cout << pre << endl;
}
