#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);
long long read_long() {
  long long ans = 0;
  char c;
  bool started = false;
  bool is_negative = false;
  while (true) {
    c = getchar();
    if ((c < '0' || c > '9') && c != '-' && !started) continue;
    if ((c < '0' || c > '9') && c != '-' && started) break;
    if (started) {
      ans = ans * 10;
    }
    started = true;
    if (c == '-')
      is_negative = true;
    else
      ans += c - '0';
  }
  if (is_negative) ans *= -1;
  return ans;
}
int n, a[1001000], b[1001000];
vector<int> times;
map<int, int> pos;
vector<int> g[1001000];
int mt[2002000];
int T = 1, used[1001000];
bool dfs(int v) {
  if (used[v] == T) return false;
  used[v] = T;
  for (__typeof(g[v].begin()) it = g[v].begin(); it != g[v].end(); it++) {
    if (mt[*it] == -1 || dfs(mt[*it])) {
      mt[*it] = v;
      return true;
    }
  }
  return false;
}
int used1[1001000];
bool ok(int value) {
  for (int i = 0; i < n; i++) {
    g[i].clear();
    if (a[i] <= value) g[i].push_back(a[i]);
    if (b[i] <= value) g[i].push_back(b[i]);
    used1[i] = 0;
  }
  for (int i = 0; i < (int)times.size(); i++) mt[i] = -1;
  for (int i = 0; i < n; i++) {
    for (__typeof(g[i].begin()) it = g[i].begin(); it != g[i].end(); it++) {
      if (mt[*it] == -1) {
        mt[*it] = i;
        used1[i] = 1;
        break;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    dfs(i);
    T++;
  }
  for (int i = 0; i < (int)times.size(); i++) ans += (mt[i] != -1);
  return ans == n;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", a + i, b + i);
    times.push_back(a[i]);
    times.push_back(b[i]);
  }
  sort(times.begin(), times.end());
  times.resize(unique(times.begin(), times.end()) - times.begin());
  for (int i = 0; i < (int)times.size(); i++) {
    pos[times[i]] = i;
  }
  for (int i = 0; i < n; i++) {
    a[i] = pos[a[i]];
    b[i] = pos[b[i]];
  }
  int ans = -1;
  int l = 0, r = (int)times.size() - 1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (ok(mid)) {
      ans = times[mid];
      r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%d\n", ans);
  return 0;
}
