#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)(1000000007);
const double eps = 1e-9;
const double pi = 3.1415926535897932384626;
long long gcd(long long a, long long b) { return (b ? gcd(b, a % b) : a); }
bool isprime(int n) {
  if (n == 1) return false;
  for (long long i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return false;
  }
  return true;
}
int modExp(int b, int e, int m) {
  int x = 1;
  while (e != 0) {
    if (e % 2 == 1) x = (x * b) % m;
    b = (b * b) % m;
    e = e / 2;
  }
  return x;
}
unsigned long long fact(unsigned long long n) {
  unsigned long long ret = 1;
  for (long long i = 1; i <= n; i++) {
    ret *= i;
  }
  return ret;
}
int ans = 0;
int main() {
  long long n;
  cin >> n;
  vector<pair<long long, long long> > vp;
  for (long long i = 0; i <= n - 1; i++) {
    int a, b;
    cin >> a >> b;
    vp.push_back(make_pair(a, b));
  }
  sort(vp.begin(), vp.end());
  ans = vp[0].second;
  for (long long i = 1; i <= n - 1; i++) {
    if (vp[i].second >= ans)
      ans = vp[i].second;
    else
      ans = vp[i].first;
  }
  cout << ans << endl;
  return 0;
}
