#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e18;
const long long mod = (long long)1e9 + 7;
const long double eps = 1e-9;
int bit[100010];
int N = 0;
void init(int n) {
  N = n;
  for (int i = 0; i < N; i++) bit[i] = 0;
}
void add(int k, int a) {
  while (k <= N) {
    bit[k] += a;
    k += k & -k;
  }
}
int sum(int k) {
  int ret = 0;
  while (k > 0) {
    ret += bit[k];
    k -= k & -k;
  }
  return ret;
}
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > a(n, make_pair(0, 0));
  for (int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
  sort(a.begin(), a.end());
  while (a.size() > 0 && n < a[n - 1].first) a.erase(a.begin() + (--n));
  int big = 0;
  for (int i = 0; i < n; i++) big = max(big, a[i].second);
  big++;
  init(big);
  int ret = 1;
  for (int i = 0; i < n; i++) {
    add(a[i].second, 1);
    ret = max(ret, i + 2 - sum(a[i].first));
  }
  cout << ret - 1 << endl;
  return 0;
}
