#include <bits/stdc++.h>
using namespace std;
int n, m, i, u, nr, sol;
int h[200005], ok[200005], ind[200005], ff[200005];
pair<int, int> v[200005];
int cmp(int a, int b) { return v[a].first > v[b].first; }
int cmp2(int a, int b) { return v[a].second < v[b].second; }
void upd() {
  int c = nr, p = c / 2;
  while (p > 0 && v[h[c]].second > v[h[p]].second) {
    swap(h[p], h[c]);
    c = p;
    p = c / 2;
  }
}
void elim() {
  int p = 1, c = 2;
  while (c <= nr) {
    if (c + 1 <= nr && v[h[c + 1]].second > v[h[c]].second) {
      c++;
    }
    if (v[h[c]].second > v[h[p]].second) {
      swap(h[p], h[c]);
      p = c;
      c = p + p;
    } else {
      break;
    }
  }
}
int main() {
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> v[i].first >> v[i].second;
    ind[i] = i;
  }
  sort(ind + 1, ind + n + 1, cmp);
  u = 1;
  for (i = m; i >= 1; i--) {
    while (v[ind[u]].first == i) {
      h[++nr] = ind[u];
      upd();
      u++;
    }
    if (nr != 0) {
      ff[i] = 1;
      ok[h[1]] = 1;
      swap(h[1], h[nr]);
      nr--;
      elim();
    }
  }
  nr = 1;
  for (i = 1; i <= n; i++) {
    if (ff[i] == 1) {
      ff[i] = 0;
      ff[nr] = 1;
      nr++;
    }
  }
  for (i = 1; i <= n; i++) {
    ind[i] = i;
    sol += ok[i];
  }
  nr = 0;
  sort(ind + 1, ind + n + 1, cmp2);
  u = 1;
  for (i = 1; i <= m; i++) {
    while (v[ind[u]].second == i) {
      if (ok[ind[u]] == 0) {
        nr++;
      }
      u++;
    }
    if (nr > 0 && ff[i] == 0) {
      sol++;
      nr--;
    }
  }
  cout << n - sol;
}
