#include <bits/stdc++.h>
using namespace std;
int l[200005], r[200005];
pair<int, int> p[200005];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &l[i], &r[i]);
    p[i] = pair<int, int>(l[i], r[i]);
  }
  sort(p + 1, p + 1 + n);
  multiset<int> ms1, ms2;
  int L = 0;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (p[i].first == 0 && p[i].second == m + 1) {
      ans++;
      continue;
    } else if (p[i].first == 0) {
      ms1.insert(p[i].second);
    } else if (L < m && L + 1 <= p[i].first) {
      L++;
      ms2.insert(p[i].second);
    } else {
      if (!ms2.empty() && *ms2.begin() < p[i].second) {
        ms1.insert(*ms2.begin());
        ms2.erase(ms2.begin());
      } else {
        ms1.insert(p[i].second);
      }
    }
  }
  for (auto its = ms1.begin(); its != ms1.end(); its++) {
    int r = *its;
    if (r == m + 1 || L == m)
      ans++;
    else {
      L++;
      L = max(L, r);
    }
  }
  printf("%d\n", ans);
}
