#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline bool umn(T1& a, T2 b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
inline bool umx(T1& a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
struct Input {
  int n;
  vector<pair<int, int> > a;
  bool read() {
    if (!(cin >> n)) {
      return false;
    }
    for (int i = 0; i < int(n); ++i) {
      int x, y;
      scanf("%d%d", &x, &y);
      a.push_back(make_pair(x, y));
    }
    return 1;
  }
  void init(Input const& input) { *this = input; }
};
struct Data : Input {
  int ans;
  void write() { printf("%d\n", ans); }
  virtual void clear(){};
  virtual void solve(){};
};
struct Solution : Data {
  bool ok(int t) {
    vector<pair<int, int> > b;
    for (int i = 0; i < int(int((a).size())); ++i) {
      if (a[i].first <= t) {
        b.push_back(make_pair(a[i].first, a[i].first));
      } else if (a[i].second <= t) {
        b.push_back(make_pair(a[i].second, a[i].first));
      } else {
        return false;
      }
    }
    sort((b).begin(), (b).end());
    int last = 0;
    for (int i = 0; i < int(int((b).size())); ++i) {
      if (b[i].second < last) {
        return false;
      }
      last = b[i].second;
    }
    return true;
  }
  void solve() {
    vector<int> c;
    for (int i = 0; i < int(int((a).size())); ++i) {
      c.push_back(a[i].first);
      c.push_back(a[i].second);
    }
    sort((c).begin(), (c).end());
    c.resize(unique((c).begin(), (c).end()) - c.begin());
    ;
    int l = -1, r = int((c).size()) - 1;
    while (l + 1 < r) {
      int m = (l + r) / 2;
      if (ok(c[m])) {
        r = m;
      } else {
        l = m;
      }
    }
    ans = c[r];
  }
  void clear() { *this = Solution(); }
};
Solution sol;
int main() {
  cout.precision(20);
  cout.setf(ios::fixed | ios::showpoint);
  sol.read();
  sol.solve();
  sol.write();
  return 0;
}
