#include <bits/stdc++.h>
using namespace std;
struct node {
  int d[2];
};
node q[5010];
bool cmp(node x, node y) {
  if (x.d[0] != y.d[0]) return x.d[0] < y.d[0];
  return x.d[1] < y.d[1];
}
int main() {
  int n, i, j = 1;
  cin >> n;
  for (i = 0; i < n; i++) cin >> q[i].d[0] >> q[i].d[1];
  sort(q, q + n, cmp);
  for (i = 1; i < n; i++) {
    if (q[i].d[1] >= q[i - 1].d[j])
      j = 1;
    else
      j = 0;
  }
  cout << q[n - 1].d[j] << endl;
  return 0;
}
