#include <bits/stdc++.h>
using namespace std;
struct State {
  int x, y;
  State(int x_, int y_) {
    x = x_;
    y = y_;
  }
  State() {}
};
bool operator<(const State& a, const State& b) {
  if (a.x > b.x)
    return true;
  else if (a.x < b.x)
    return false;
  return a.y > b.y;
}
int main() {
  int n;
  priority_queue<State> q;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    q.push(State(a, +1));
    q.push(State(b, -1));
  }
  q.push(State(n + 10, +1));
  int ans = 0, num = 0, f = 1;
  while (!q.empty()) {
    State s = q.top();
    q.pop();
    while (f != s.x) {
      if (f - 1 <= num) ans = f - 1;
      f++;
    }
    num += s.y;
  }
  cout << ans << endl;
}
