#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
struct my {
  int a;
  int b;
};
vector<my> v;
bool operator<(const my &a, const my &b) {
  if (a.a != b.a) {
    return a.a < b.a;
  } else {
    return a.b < b.b;
  }
}
int main() {
  int n;
  int i;
  cin >> n;
  v.resize(n);
  for (i = 0; i < n; ++i) {
    cin >> v[i].a >> v[i].b;
  }
  sort(v.begin(), v.end());
  int mn = 0;
  i = 0;
  int time = 0;
  int lw = 0;
  while (i < n) {
    lw = v[i].b;
    while ((i < n - 1) && (v[i].a == v[i + 1].a)) {
      ++i;
    }
    if (time <= lw) {
      time = max(time, min(v[i].a, v[i].b));
    } else {
      time = v[i].a;
    }
    ++i;
  }
  cout << time;
  return 0;
}
