#include <bits/stdc++.h>
using namespace std;
const int ONE = 1000005;
const int INF = 2147483640;
int get() {
  int res = 1, Q = 1;
  char c;
  while ((c = getchar()) < 48 || c > 57)
    if (c == '-') Q = -1;
  if (Q) res = c - 48;
  while ((c = getchar()) >= 48 && c <= 57) res = res * 10 + c - 48;
  return res * Q;
}
int n, m;
int sum[ONE];
int x, y;
struct power {
  int x, y;
} a[ONE];
bool cmp(const power &a, const power &b) { return a.x - a.y < b.x - b.y; }
int vis[ONE], Ans;
int main() {
  n = get(), m = get();
  for (int i = 1; i <= n; i++) {
    a[i].x = x = get(), a[i].y = y = get();
    if (x != 0) sum[1]++, sum[x + 1]--;
    if (y != m + 1) sum[y]++, sum[m + 1]--;
  }
  for (int i = 1; i <= m; i++) sum[i] += sum[i - 1];
  sort(a + 1, a + n + 1, cmp);
  for (int i = 1; i <= n; i++) {
    int pos = 0, minn = INF;
    for (int j = 1; j <= a[i].x; j++)
      if (!vis[j] && sum[j] < minn) minn = sum[j], pos = j;
    for (int j = a[i].y; j <= m; j++)
      if (!vis[j] && sum[j] < minn) minn = sum[j], pos = j;
    if (!pos) {
      Ans++;
      continue;
    }
    vis[pos] = 1;
  }
  cout << Ans;
}
