#include <bits/stdc++.h>
using namespace std;
struct xx {
  int x, y;
} a[10000];
bool cmp(xx a, xx b) { return a.x < b.x || a.x == b.x && a.y < b.y; }
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d%d", &a[i].x, &a[i].y);
  sort(a + 1, a + n + 1, cmp);
  int x = -1;
  for (int i = 1; i <= n; i++) {
    if (a[i].y >= x)
      x = a[i].y;
    else
      x = a[i].x;
  }
  cout << x << endl;
}
