#include <bits/stdc++.h>
using namespace std;
int n, i, ans;
bool ok;
struct qwe {
  int x, y;
} a[10001];
bool cmp(qwe a, qwe b) { return (a.x < b.x) || (a.x == b.x && a.y < b.y); }
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i].x >> a[i].y;
  sort(a + 1, a + n + 1, cmp);
  ans = min(a[1].x, a[1].y);
  for (i = 2; i <= n; i++) {
    if (a[i].x < a[i].y)
      if (a[i].x >= ans)
        ans = a[i].x;
      else
        ans = a[i].y;
    else if (a[i].x > a[i].y)
      if (a[i].y >= ans)
        ans = a[i].y;
      else
        ans = a[i].x;
  }
  cout << ans;
}
