#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (auto i = begin(v); i != end(v); i++)
    os << *i << (i == end(v) - 1 ? "" : " ");
  return os;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto i = begin(v); i != end(v); i++) is >> *i;
  return is;
}
class HopcroftCarpMatch {
 private:
  vector<vector<int>> lhs_edges;
  int left_cnt, right_cnt;
  vector<int> bfs_dists;
  vector<int> left_assignment, right_assignment;
  bool bfs() {
    queue<int> bfs_q;
    bfs_dists.assign(left_cnt, -1);
    for (int i = 0; i < left_cnt; i++) {
      if (left_assignment[i] < 0) {
        bfs_dists[i] = 0;
        bfs_q.push(i);
      }
    }
    bool found = false;
    while (bfs_q.size() > 0) {
      int id = bfs_q.front();
      bfs_q.pop();
      for (int right_id : lhs_edges[id]) {
        int corr_left = right_assignment[right_id];
        if (corr_left == -1) {
          found = true;
          continue;
        }
        if (bfs_dists[corr_left] < 0) {
          bfs_dists[corr_left] = bfs_dists[id] + 1;
          bfs_q.push(corr_left);
        }
      }
    }
    return found;
  }
  bool dfs(int v) {
    if (bfs_dists[v] < 0) return false;
    int my_dist = bfs_dists[v];
    bfs_dists[v] = -1;
    for (int right_i : lhs_edges[v]) {
      if (right_assignment[right_i] == -1 ||
          (bfs_dists[right_assignment[right_i]] == (my_dist + 1) &&
           dfs(right_assignment[right_i]))) {
        left_assignment[v] = right_i;
        right_assignment[right_i] = v;
        return true;
      }
    }
    return false;
  }

 public:
  HopcroftCarpMatch(const int left, const int right) {
    lhs_edges.resize(left);
    left_cnt = left;
    right_cnt = right;
  }
  void add_edge(const int left, const int right) {
    assert(left >= 0 && left < lhs_edges.size());
    assert(right >= 0 && right < right_cnt);
    lhs_edges[left].push_back(right);
  }
  vector<int> max_matching() {
    left_assignment.assign(left_cnt, -1);
    right_assignment.assign(right_cnt, -1);
    while (bfs()) {
      for (int i = 0; i < left_cnt; i++) {
        if (left_assignment[i] == -1) dfs(i);
      }
    }
    return left_assignment;
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  scanf("%d", &n);
  vector<pair<int, int>> pairs;
  vector<int> days;
  for (int i = 0; i < n; i++) {
    int aa, bb;
    scanf("%d %d", &aa, &bb);
    pairs.push_back({aa, bb});
    days.push_back(aa);
    days.push_back(bb);
  }
  sort((days).begin(), (days).end());
  (days).erase(unique((days).begin(), (days).end()), (days).end());
  map<int, int> day_to_id;
  for (int i = 0; i < days.size(); i++) day_to_id[days[i]] = i;
  for (auto& x : pairs) {
    x.first = day_to_id[x.first];
    x.second = day_to_id[x.second];
  }
  int left = 0, right = days.size();
  while (left < right) {
    int m = (left + right) / 2;
    if (m < n) {
      left = m + 1;
      continue;
    }
    HopcroftCarpMatch hm(n, m + 1);
    for (int i = 0; i < n; i++) {
      if (pairs[i].first <= m) hm.add_edge(i, pairs[i].first);
      if (pairs[i].second <= m) hm.add_edge(i, pairs[i].second);
    }
    bool any = false;
    auto ret = hm.max_matching();
    for (int x : ret) {
      if (x < 0) {
        any = true;
        break;
      }
    }
    if (any) {
      left = m + 1;
    } else {
      right = m;
    }
  }
  if (left >= days.size())
    cout << -1;
  else
    cout << days[left];
  return 0;
}
