#include <bits/stdc++.h>
using namespace std;
struct point {
  int x, y;
  inline bool operator<(const point t) const { return x < t.x; }
};
point p[300000];
int tree[1000000];
int g[300000];
int i, k, m, n, s;
inline bool inserttree(int l, int r, int x, int y, int z, int node) {
  if (tree[node] >= z) return false;
  if (l == r) {
    if (tree[node]) k++, g[k] = tree[node];
    tree[node] = z;
    return true;
  }
  int mid = (l + r) >> 1;
  bool b;
  if ((l == x) && (r == y))
    if (tree[node << 1] < z)
      return b = inserttree(l, mid, x, mid, z, node << 1),
             tree[node] = min(tree[node << 1], tree[node << 1 | 1]), b;
    else
      return b = inserttree(mid + 1, r, mid + 1, y, z, node << 1 | 1),
             tree[node] = min(tree[node << 1], tree[node << 1 | 1]), b;
  if (y <= mid)
    return b = inserttree(l, mid, x, y, z, node << 1),
           tree[node] = min(tree[node << 1], tree[node << 1 | 1]), b;
  if (x > mid)
    return b = inserttree(mid + 1, r, x, y, z, node << 1 | 1),
           tree[node] = min(tree[node << 1], tree[node << 1 | 1]), b;
  if (b = inserttree(l, mid, x, mid, z, node << 1))
    return tree[node] = min(tree[node << 1], tree[node << 1 | 1]), b;
  else
    return b = inserttree(mid + 1, r, mid + 1, y, z, node << 1 | 1),
           tree[node] = min(tree[node << 1], tree[node << 1 | 1]), b;
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d%d", &p[i].x, &p[i].y);
  sort(p + 1, p + n + 1);
  for (i = 1; i <= n; i++)
    if ((!p[i].x) || (!inserttree(1, m, 1, p[i].x, p[i].y, 1)))
      k++, g[k] = p[i].y;
  sort(g + 1, g + k + 1);
  for (i = k; i > 0; i--)
    if ((g[i] > m) || (!inserttree(1, m, g[i], m, 1, 1))) s++;
  printf("%d", s);
  return 0;
}
