#include <bits/stdc++.h>
using namespace std;
pair<int, int> p[5005];
int n;
int srt(pair<int, int> a, pair<int, int> b) {
  return (a.first != b.first ? a.first < b.first : a.second < b.second);
}
void read() {
  int i;
  cin >> n;
  for (i = 0; i < n; i++) cin >> p[i].first >> p[i].second;
  sort(p, p + n, srt);
}
void calc() {
  int i, now = 0;
  for (i = 0; i < n; i++) {
    if (now > p[i].second) {
      now = p[i].first;
    } else if (now < p[i].second)
      now = p[i].second;
  }
  cout << now << endl;
  return;
}
int main() {
  read();
  calc();
  return 0;
}
