#include <bits/stdc++.h>
using namespace std;
int N, M;
int l[200005], r[200005];
int c[200005], d[200005];
int F, f[200005];
int match(int x) {
  if (f[x] == F) return 0;
  f[x] = F;
  for (int i = 1; i <= l[x]; i++)
    if (!d[i]) {
      d[i] = x;
      c[x] = i;
      return 1;
    }
  for (int i = r[x]; i <= M; i++)
    if (!d[i]) {
      d[i] = x;
      c[x] = i;
      return 1;
    }
  for (int i = 1; i <= l[x]; i++)
    if (match(d[i])) {
      d[i] = x;
      c[x] = i;
      return 1;
    }
  for (int i = r[x]; i <= M; i++)
    if (match(d[i])) {
      d[i] = x;
      c[x] = i;
      return 1;
    }
  return 0;
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; i++) scanf("%d%d", &l[i], &r[i]);
  bool newMatch = true;
  while (newMatch) {
    F++;
    newMatch = false;
    for (int i = 1; i <= N; i++)
      if (!c[i])
        if (match(i)) newMatch = true;
  }
  int cnt = 0;
  for (int i = 1; i <= N; i++)
    if (c[i]) cnt++;
  printf("%d\n", N - cnt);
  return 0;
}
