#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long size = 5005;
int arr[size];
int temp[size];
bool comp(pair<int, int> p1, pair<int, int> p2) {
  if (p1.first == p2.first) return p1.second < p2.second;
  return p1.first < p2.first;
}
int main() {
  vector<pair<int, int> > vi;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    vi.push_back(make_pair(x, y));
    arr[i] = x;
  }
  sort(vi.begin(), vi.end(), comp);
  int ans = -1;
  for (int i = 0; i < n; i++) {
    if (vi[i].second >= ans)
      ans = vi[i].second;
    else
      ans = vi[i].first;
  }
  cout << ans << endl;
}
