#include <bits/stdc++.h>
using namespace std;
const int xx[] = {0, 1, 0, -1, -1, 1, -1, 1};
const int yy[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int kx[] = {-2, -1, 1, 2, 2, 1, -1, -2};
const int ky[] = {1, 2, 2, 1, -1, -2, -2, -1};
pair<int, int> arr[5006];
int main() {
  int i, j, n, k, mx1, mx2, ans;
  scanf("%d", &n);
  mx1 = mx2 = -1;
  for (i = 0; i < n; i++) {
    scanf("%d%d", &arr[i].first, &arr[i].second);
  }
  ans = -1;
  bool key = 1;
  sort(arr, arr + n);
  for (i = 0; i < n; i++) {
    if (ans <= arr[i].second)
      ans = arr[i].second;
    else
      ans = arr[i].first;
  }
  printf("%d\n", ans);
  return 0;
}
