#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 100;
int n;
pair<int, int> p[maxn];
int check(int x) {
  map<int, int> mp;
  for (int i = n; i >= 1; i--) {
    if (p[i].first > x)
      return 0;
    else if (p[i].second > x) {
      if (mp[p[i].first]) return 0;
      mp[p[i].first] = 1;
    } else {
      if (!mp[p[i].second] && !mp[p[i].first])
        mp[p[i].second] = 1;
      else if (!mp[p[i].first])
        mp[p[i].first] = 1;
      else if (!mp[p[i].second])
        mp[p[i].second] = 1;
      else
        return 0;
    }
  }
  return 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", &p[i].first, &p[i].second);
  sort(p + 1, p + n + 1);
  int l = 1, r = 1e9 + 100;
  int ans = -1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  printf("%d\n", ans);
}
