#include <bits/stdc++.h>
using namespace std;
struct less_than_key {
  inline bool operator()(const pair<int, int>& s0, const pair<int, int>& s1) {
    return (s0.first < s1.first ||
            (s0.first == s1.first && s0.second < s1.second));
  }
};
int n;
vector<pair<int, int> > arr;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    arr.push_back(make_pair(a, b));
  }
  sort(arr.begin(), arr.end(), less_than_key());
  int max = 0;
  for (size_t i = 0; i < arr.size(); i++) {
    if (arr[i].second >= max) {
      max = arr[i].second;
    } else {
      max = arr[i].first;
    }
  }
  cout << max;
  return 0;
}
