#include <bits/stdc++.h>
using namespace std;
int main() {
  array<int, 100000> friends = {
      1,
      0,
  };
  int n = 0;
  cin >> n;
  int max_index = 0;
  for (auto i = 0; i < n; ++i) {
    int under;
    int over;
    cin >> under >> over;
    friends[under - 1]++;
    friends[over]--;
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    friends[i] = friends[i] + friends[i - 1];
    if (friends[i] > ans && friends[i] - i >= 0) {
      ans = max(ans, friends[i]);
    }
  }
  ans = max(ans - 2, 0);
  cout << ans << endl;
  return 0;
}
