#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, m, L[400007], R[400007], ans = 0;
int last[400007], nt[400007];
bool vis[400007];
pair<int, int> pos[400007];
void del(int x) {
  nt[last[x]] = nt[x];
  last[nt[x]] = last[x];
  vis[x] = false;
}
int pre(int x) {
  if (vis[x]) return x;
  while (x > 0) {
    x = last[x];
    if (vis[x]) return x;
  }
  return x;
}
int nxt(int x) {
  if (vis[x]) return x;
  while (x < m + 1) {
    x = nt[x];
    if (vis[x]) return x;
  }
  return x;
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) L[i] = read(), R[i] = read();
  for (int i = 1; i <= n; i++) pos[i] = make_pair(L[i], -R[i]);
  sort(pos + 1, pos + n + 1);
  for (int i = 1; i <= m; i++) last[i] = i - 1, nt[i] = i + 1;
  nt[0] = 1, last[m + 1] = m;
  last[0] = 0, nt[m + 1] = m + 1;
  memset(vis, true, sizeof(vis));
  for (int i = 1; i <= n; i++) {
    int x = pre(pos[i].first), y = nxt(-pos[i].second);
    if (x > 0)
      del(x);
    else if (y < m + 1)
      del(y);
    else
      ++ans;
  }
  printf("%d\n", ans);
  return 0;
}
