#include <bits/stdc++.h>
using namespace std;
struct p {
  int a, b;
};
bool operator<(p x, p y) {
  if (x.a < y.a)
    return true;
  else if (x.a == y.a && x.b < y.b)
    return true;
  else
    return false;
}
int main() {
  int n;
  cin >> n;
  vector<p> sample(n);
  for (int i = 0; i < n; i++) {
    int temp1, temp2;
    cin >> temp1 >> temp2;
    sample[i].a = temp1;
    sample[i].b = temp2;
  }
  sort(sample.begin(), sample.end());
  int mina = sample[sample.size() - 1].a;
  int minb = sample[sample.size() - 1].b;
  for (int i = sample.size() - 2; i >= 0; i--) {
    int tempa;
    if (sample[i].a <= sample[i + 1].b)
      tempa = minb;
    else
      tempa = mina;
    mina = tempa;
    int tempb;
    if (sample[i].b <= sample[i + 1].b)
      tempb = minb;
    else
      tempb = mina;
    minb = tempb;
  }
  cout << min(mina, minb);
}
