#include <bits/stdc++.h>
using namespace std;
int n, a[5001], b[5001];
pair<int, int> c[5001];
int prevday;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i] >> b[i];
    c[i].first = a[i];
    c[i].second = b[i];
  }
  sort(c + 1, c + n + 1);
  for (int i = 1; i <= n; ++i) {
    int x = min(c[i].first, c[i].second);
    if (x >= prevday)
      prevday = x;
    else
      prevday = max(c[i].first, c[i].second);
  }
  cout << prevday;
}
