#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
const int inf = 1e9 + 7;
vector<pair<int, int> > res;
int n;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    res.push_back(make_pair(u, v));
  }
  sort(res.begin(), res.end());
  int tmp = 0;
  for (int i = 0; i < n; i++) {
    int tam = min(res[i].first, res[i].second);
    if (tam >= tmp)
      tmp = tam;
    else
      tmp = max(res[i].first, res[i].second);
  }
  cout << tmp;
  return 0;
}
