#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.1415926535897932384626433832795l;
template <typename T>
inline auto sqr(T x) -> decltype(x * x) {
  return x * x;
}
template <typename T>
inline T abs(T x) {
  return x > T() ? x : -x;
}
template <typename T1, typename T2>
inline bool umx(T1& a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
inline bool umn(T1& a, T2 b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int N = 5010;
struct Input {
  int n;
  int l[N], r[N];
  bool read() {
    if (scanf("%d", &n) != 1) return 0;
    for (int i = 0; i < int(n); ++i) {
      scanf("%d %d", &r[i], &l[i]);
    }
    return 1;
  }
  void init(const Input& input) { *this = input; }
};
struct Data : Input {
  int ans;
  void write() { cout << ans << endl; }
  virtual void solve() {}
  virtual void clear() { *this = Data(); }
};
struct Solution : Data {
  int ord[N];
  void solve() {
    ans = 0;
    for (int i = 0; i < int(n); ++i) ord[i] = i;
    sort(ord, ord + n, [&](int i, int j) {
      return (r[i] < r[j] || (r[i] == r[j] && l[i] < l[j]));
    });
    int tekmaxx = -1;
    for (int i = 0; i < int(n); ++i) {
      int idx = ord[i];
      if (l[idx] >= tekmaxx) {
        umx(ans, l[idx]);
        tekmaxx = l[idx];
      } else {
        umx(ans, r[idx]);
        tekmaxx = r[idx];
      }
    }
  }
  void clear() { *this = Solution(); }
};
Solution sol;
int main() {
  cout.setf(ios::showpoint | ios::fixed);
  cout.precision(20);
  sol.read();
  sol.solve();
  sol.write();
  return 0;
}
