#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int ans = 1;
  cin >> N;
  vector<pair<int, int> > friends;
  queue<pair<int, int> > q;
  for (int i = 0; i < (N); i++) {
    int t1, t2;
    cin >> t1 >> t2;
    friends.push_back(make_pair(t1, t2));
  }
  sort(friends.begin(), friends.end());
  for (int i = 0; i < (N); i++) {
    if (q.empty()) {
      q.push(friends[i]);
      if (q.front().first <= q.size()) {
        ans = max(ans, int(q.size()));
      }
    } else if (friends[i].first > N + 1)
      continue;
    else if (q.front().second < friends[i].first) {
      while (1) {
        if (q.empty()) break;
        if (q.front().second >= friends[i].first) break;
        q.pop();
      }
      q.push(friends[i]);
    } else if (q.front().second == friends[i].first) {
      q.pop();
      q.push(friends[i]);
    } else {
      q.push(friends[i]);
      if (q.front().first <= q.size()) {
        ans = max(ans, int(q.size()));
      }
    }
  }
  cout << ans - 1 << endl;
  return 0;
}
