#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-7;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * (b / (gcd(a, b))); }
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline long long toLL(string s) {
  long long v;
  istringstream sin(s);
  sin >> v;
  return v;
}
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
using namespace std;
vector<pair<long long, long long> > vec;
int N;
int main() {
  std::ios_base::sync_with_stdio(false);
  cin >> N;
  long long u, v;
  for (int i = 0; i < (int)N; i++) {
    cin >> u >> v;
    vec.push_back(make_pair(u, v));
  }
  sort(vec.begin(), vec.end());
  int fake = 0, real = 0;
  for (int k = 0; k < ((int)((vec).size())); k++) {
    pair<long long, long long> curr = vec[k];
    if (curr.second >= fake) {
      fake = curr.second;
      real = curr.first;
    } else {
      fake = curr.first;
      real = curr.first;
    }
  }
  cout << fake << "\n";
}
