#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int maxc = 26;
const long long mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double eps = 1e-5;
inline int read() {
  int f = 1, x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  return f * x;
}
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long poww(long long x, long long y) {
  long long ans = 1;
  while (y) {
    if (y & 1) ans = ans * x;
    x = x * x;
    y >>= 1;
  }
  return ans;
}
int n;
pair<int, int> t[5005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> t[i].first >> t[i].second;
  sort(t, t + n);
  int ans = t[0].second;
  for (int i = 0; i < n - 1; i++) {
    int d = t[i + 1].second;
    if (ans > d)
      ans = t[i + 1].first;
    else
      ans = t[i + 1].second;
  }
  cout << ans << endl;
  return 0;
}
