#include <bits/stdc++.h>
using namespace std;
struct node {
  int x1, y1;
} ar[500101];
bool cmp(node &b1, node &b2) {
  if (b1.x1 == b2.x1) return b1.y1 < b2.y1;
  return b1.x1 < b2.x1;
}
int main() {
  long long q, i, j, k, v, c = 0, p1, p2, t, n, x, y, p;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> ar[i].x1 >> ar[i].y1;
  }
  sort(ar, ar + n, cmp);
  for (i = 0; i < n; i++) {
    if (i == 0) {
      p = min(ar[i].x1, ar[i].y1);
    } else {
      p1 = min(ar[i].x1, ar[i].y1);
      if (p1 >= p) {
        p = p1;
      } else if (ar[i].x1 > ar[i].y1) {
        p = ar[i].x1;
      } else {
        p = ar[i].y1;
      }
    }
  }
  cout << p << endl;
  return 0;
}
