#include <bits/stdc++.h>
using namespace std;
struct rec {
  int x, y;
} a[6000];
int Max, i, n;
int CMP(rec i, rec j) { return i.x < j.x || (i.x == j.x && i.y < j.y); }
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d%d", &a[i].x, &a[i].y);
  sort(a + 1, a + n + 1, CMP);
  for (i = 1; i <= n; i++) {
    if (a[i].y >= Max)
      Max = a[i].y;
    else
      Max = a[i].x;
  }
  cout << Max;
  return 0;
}
