#include <bits/stdc++.h>
using namespace std;
long long _pow(long long base, long long exp) {
  return exp == 0 ? 1 : base * _pow(base, exp - 1);
}
string int_to_str(int x) {
  string xs;
  stringstream ss;
  ss << x;
  xs = ss.str();
  return xs;
}
int str_vec_find(string x, vector<string> y) {
  vector<string>::iterator it;
  it = find(y.begin(), y.end(), x);
  int pos = distance(y.begin(), it);
  return pos;
}
int main() {
  long long temp, tempa, tempb, maxa, maxb;
  vector<long long> a, b;
  int n;
  cin >> n;
  maxa = maxb = -1;
  for (int i = 0; i < n; i++) {
    cin >> tempa >> tempb;
    if (tempa >= maxa) maxa = tempa;
    if (tempb >= maxb) maxb = tempb;
    a.push_back(tempa);
    b.push_back(tempb);
  }
  for (int w = 0; w < b.size(); w++) {
    for (int r = 0; r < b.size() - 1; r++) {
      if (a[r] > a[r + 1]) {
        temp = a[r];
        a[r] = a[r + 1];
        a[r + 1] = temp;
        temp = b[r];
        b[r] = b[r + 1];
        b[r + 1] = temp;
      }
    }
  }
  if (n == 1)
    cout << maxb << endl;
  else {
    long long stamp = b[0];
    for (int i = 1; i < n; i++) {
      if (b[i] >= stamp)
        stamp = b[i];
      else {
        if (a[i] != a[i - 1]) stamp = a[i];
      }
    }
    cout << stamp << endl;
  }
  return 0;
}
