#include <bits/stdc++.h>
const int N = 2e5 + 10;
int n, m, x[N], l[N], r[N], ans;
bool v[N];
inline bool h(int cur) {
  for (int i = 1; i <= l[cur]; i++)
    if (!v[i]) {
      v[i] = true;
      if (x[i] == -1 || h(x[i])) {
        x[i] = cur;
        return true;
      }
    }
  for (int i = r[cur]; i <= m; i++)
    if (!v[i]) {
      v[i] = true;
      if (x[i] == -1 || h(x[i])) {
        x[i] = cur;
        return true;
      }
    }
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d%d", l + i, r + i);
  memset(x, -1, sizeof x);
  for (int i = 1; i <= n; i++) {
    memset(v, false, sizeof v);
    if (h(i)) ans++;
  }
  printf("%d\n", n - ans);
  return 0;
}
