#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 7;
struct Node {
  int l, r;
} a[maxn];
int n, m, size, ans, cur, v[maxn];
bool vis[maxn];
bool cmp(Node a, Node b) {
  if (a.l == b.l)
    return a.r > b.r;
  else
    return a.l < b.l;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d%d", &a[i].l, &a[i].r);
  sort(a + 1, a + n + 1, cmp);
  memset(vis, 0, sizeof(vis));
  cur = 1;
  for (int i = 1; i <= n; i++)
    if (a[i].l >= cur)
      vis[i] = 1, ++cur;
    else
      v[++size] = m - a[i].r + 1;
  sort(v + 1, v + size + 1);
  ans = 0, cur = 1;
  for (int i = 1; i <= size; i++)
    if (v[i] >= cur)
      ++cur;
    else
      ++ans;
  printf("%d\n", ans);
  return 0;
}
