#include <bits/stdc++.h>
using namespace std;
struct t {
  long long int x;
  long long int y;
  long long int minn;
} a[5010];
bool cmp(t a, t b) {
  if (a.x != b.x) {
    return a.x < b.x;
  }
  return a.y < b.y;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].x >> a[i].y;
  }
  sort(a + 1, a + 1 + n, cmp);
  int date = min(a[1].x, a[1].y);
  for (int i = 1; i <= n; i++) {
    if (min(a[i].x, a[i].y) >= date) {
      date = min(a[i].x, a[i].y);
    } else {
      date = max(a[i].x, a[i].y);
    }
  }
  cout << date << endl;
  return 0;
}
