#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 8;
const double pi = 3.14159265359;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int fac(int x) {
  if (x == 0) return 1;
  return (x * fac(x - 1));
}
template <class T>
T gcd(T x, T y) {
  T gc;
  for (T i = 1; i <= x && i <= y; i++) {
    if (x % i == 0 && y % i == 0) gc = i;
  }
  return gc;
}
template <class T>
T fac(T n) {
  T res = 1, i;
  for (i = 2; i <= n; i++) res *= i;
  return res;
}
template <class T>
T lcm(T a, T b) {
  return (a * b) / gcd(a, b);
}
string tostring(int a) {
  string ans;
  while (a) {
    ans += char(a % 10 + '0');
    a /= 10;
  }
  return ans;
}
void solve() {
  int n;
  cin >> n;
  vector<pair<int, int> > p(n);
  for (int i = 0; i < n; ++i) cin >> p[i].first >> p[i].second;
  sort((p).begin(), (p).end());
  int mini = min(p[0].first, p[0].second);
  for (int i = 1; i < n; ++i) {
    if (min(p[i].first, p[i].second) >= mini)
      mini = min(p[i].first, p[i].second);
    else
      mini = max(p[i].first, p[i].second);
  }
  cout << mini << endl;
}
int main() { solve(); }
