#include <bits/stdc++.h>
template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = std::vector<std::vector<T>>;
template <typename T>
using VVV = std::vector<std::vector<std::vector<T>>>;
template <class T>
inline T ceil(T a, T b) {
  return (a + b - 1) / b;
}
template <class T>
inline void print(T x) {
  std::cout << x << std::endl;
}
template <class T>
inline void print_vec(const std::vector<T> &v) {
  for (int i = 0; i < v.size(); ++i) {
    if (i != 0) {
      std::cout << " ";
    }
    std::cout << v[i];
  }
  std::cout << "\n";
}
template <class T>
inline bool inside(T y, T x, T H, T W) {
  return 0 <= y and y < H and 0 <= x and x < W;
}
template <class T>
inline double euclidean_distance(T y1, T x1, T y2, T x2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
template <class T>
inline double manhattan_distance(T y1, T x1, T y2, T x2) {
  return abs(x1 - x2) + abs(y1 - y2);
}
const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = {0, 1, 0, -1}, dx4 = {1, 0, -1, 0};
const std::vector<int> dy8 = {0, -1, 0, 1, 1, -1, -1, 1},
                       dx8 = {1, 0, -1, 0, 1, 1, -1, -1};
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> dp(100100, 0);
  for (int i = (0); i < ((int)N); ++i) {
    int a, b;
    cin >> a >> b;
    dp[a] += 1;
    dp[b + 1] -= 1;
  }
  for (int i = (0); i < ((int)dp.size() - 1); ++i) {
    dp[i + 1] += dp[i];
  }
  int ans = 0;
  for (int i = (0); i < ((int)dp.size()); ++i) {
    if (dp[i] >= i) {
      ans = max(ans, i - 1);
    }
  }
  print(ans);
  return 0;
}
