#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[100001];
  for (int i = 1; i < 100001; i++) {
    a[i] = 1;
  }
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    for (int i = x; i <= y; i++) {
      a[i] += 1;
    }
  }
  int ans = 0;
  for (int i = 1; i < n + 1; i++) {
    if (ans < a[i] && a[i] >= i) ans = a[i];
  }
  cout << ans - 1 << endl;
  return 0;
}
