#include <bits/stdc++.h>
using namespace std;
const int NR = 2e5 + 10;
int fa[NR], n, m;
pair<int, int> a[NR];
int gf(int x) { return fa[x] == x ? x : (fa[x] = gf(fa[x])); }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    a[i] = pair<int, int>(l, r);
  }
  sort(a + 1, a + n + 1);
  int ans = 0;
  for (int i = 1; i <= m + 1; ++i) fa[i] = i;
  for (int i = 1; i <= n; ++i) {
    int f = gf(a[i].second);
    if (f <= m)
      fa[f] = f + 1;
    else if (a[i].first && (f = gf(1)) <= a[i].first)
      fa[f] = f + 1;
    else
      ++ans;
  }
  printf("%d\n", ans);
  return 0;
}
