#include <bits/stdc++.h>
using namespace std;
const int N = 4000010;
int n, idx, vi = 0;
int a[N];
int b[N];
int idx1[N], idx2[N];
int vis[N];
int vis2[N];
int match[N];
vector<int> v, g[N];
bool DFS(int node) {
  if (vis[node] == vi || vis2[node] == 4) return false;
  vis[node] = vi;
  vis2[node]++;
  for (int i = 0; i < g[node].size(); i++) {
    if (match[g[node][i]] == -1 || DFS(match[g[node][i]])) {
      match[g[node][i]] = node;
      return true;
    }
  }
  return false;
}
bool check(int mid) {
  for (int i = 0; i < n; i++) g[i].clear(), vis2[i] = 0;
  for (int i = 0; i < (int)v.size(); i++) match[i] = -1;
  for (int i = 0; i < n; i++) {
    if (mid < a[i]) return false;
    g[i].push_back(idx1[i]);
    if (b[i] <= mid) g[i].push_back(idx2[i]);
  }
  for (int i = 0; i < n; i++) {
    vi++;
    if (!DFS(i)) return false;
  }
  return true;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a[i], &b[i]);
    v.push_back(a[i]);
    v.push_back(b[i]);
  }
  sort(v.begin(), v.end());
  v.resize(unique(v.begin(), v.end()) - v.begin());
  for (int i = 0; i < n; i++) {
    idx1[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
    idx2[i] = lower_bound(v.begin(), v.end(), b[i]) - v.begin();
  }
  int low = 1, high = 1000000010, res = -1, mid;
  while (high >= low) {
    mid = (low + high) / 2;
    if (check(mid)) {
      res = mid;
      high = mid - 1;
    } else
      low = mid + 1;
  }
  cout << res << endl;
  return 0;
}
