#include <bits/stdc++.h>
using namespace std;
const int MAX = 5500;
pair<int, int> val[MAX];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &val[i].first, &val[i].second);
  }
  sort(val, val + n);
  for (int i = 1; i < n; i++) {
    if (val[i - 1].second > val[i].second) {
      val[i].second = val[i].first;
    }
  }
  cout << val[n - 1].second << endl;
  return 0;
}
