#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
void solve() {
  int n;
  int p, q;
  cin >> n;
  vector<vector<int>> a(n, vector<int>(2, -1));
  for (int i = 0; i < n; i++) {
    cin >> p >> q;
    a[i][0] = p;
    a[i][1] = q;
  }
  sort(a.begin(), a.end());
  int curr = min(a[0][0], a[0][1]);
  for (int i = 1; i < n; i++) {
    if (curr <= min(a[i][0], a[i][1])) {
      curr = min(a[i][0], a[i][1]);
    } else {
      curr = max(a[i][0], a[i][1]);
    }
  }
  cout << curr << "\n";
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  { solve(); }
  return 0;
}
