#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  vector<pair<int, int>> friends;
  vector<int> humans;
  vector<int> nokemono;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    friends.push_back(make_pair(a, b));
  }
  for (int i = 0; i <= N + 1; i++) {
    int count = 0;
    int minn = 999999;
    for (auto range : friends) {
      if (i >= range.first && i <= range.second) {
        count++;
        if (range.second < minn) minn = range.second;
      }
    }
    count++;
    humans.push_back(count);
    if (minn == 999999) minn = 0;
    nokemono.push_back(minn);
    count = 0;
  }
  for (int i = 0; i <= N + 1; i++) {
    if (humans[i] < nokemono[i]) nokemono[i] = humans[i];
  }
  for (int i = N + 1; i >= 0; i--) {
  }
  for (int i = N + 1; i > 0; i--) {
    if (humans[i] < i) {
      nokemono[i] = 0;
    }
  }
  int maxn = 0;
  for (int i = 0; i <= N + 1; i++) {
    if (nokemono[i] > maxn) maxn = nokemono[i];
  }
  cout << max(0, maxn - 1) << endl;
  return 0;
}
