#include <bits/stdc++.h>
class Solve {
 public:
  Solve(){};
  ~Solve(){};
  void solver() {
    int ans = 0;
    int n;
    std::cin >> n;
    std::vector<std::pair<int, int>> friends(n, std::make_pair(0, 0));
    for (int(i) = 0; (i) < (n); (i)++) {
      std::cin >> friends[i].first >> friends[i].second;
      friends[i].first--;
      friends[i].second--;
    }
    for (int(i) = (1); (i) < (n + 1); (i)++) {
      int num = 0;
      for (int(j) = 0; (j) < (n); (j)++) {
        if (friends[j].first <= i && i <= friends[j].second) {
          num++;
        }
      }
      if (num >= i && ans < num) {
        ans = i;
      }
    }
    std::cout << ans << std::endl;
  }

 private:
};
int main() {
  Solve solve;
  solve.solver();
  return 0;
}
