#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29, MOD = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  int a[n], b[n];
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
  int ans = 0;
  for (int i = 1; i < n + 2; i++) {
    int cnt = 0;
    for (int j = 0; j < n; j++) {
      if (a[j] <= i and i <= b[j]) cnt++;
    }
    if (cnt == i) ans = cnt - 1;
  }
  cout << ans << endl;
  return 0;
}
