#include <bits/stdc++.h>
using namespace std;
struct NODE {
  long long x, y;
  bool operator<(const NODE& a) const {
    if (x == a.x) return y < a.y;
    return x < a.x;
  }
} a[5005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld%lld", &a[i].x, &a[i].y);
  sort(a + 1, a + 1 + n);
  long long cur = a[1].y;
  long long preX = a[1].x;
  for (int i = 2; i <= n; i++) {
    if (preX == a[i].x) {
      cur = max(cur, a[i].y);
    } else if (a[i].y >= cur) {
      cur = a[i].y;
      preX = a[i].x;
    } else {
      cur = a[i].x;
      preX = a[i].x;
    }
  }
  cout << cur << endl;
  return 0;
}
