#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 7;
struct Node {
  int l, r;
} a[maxn];
int n, m, cur, ans, vs, k, pos, T[maxn * 4];
int v[maxn];
bool vis[maxn];
bool cmp(Node a, Node b) { return a.l < b.l; }
int chos(int x, int y) {
  if (a[x].r < a[y].r)
    return y;
  else
    return x;
}
void Build_Tree(int k, int l, int r) {
  if (l == r)
    T[k] = l;
  else {
    int mid = (l + r) >> 1;
    Build_Tree((k << 1), l, mid), Build_Tree((k << 1) | 1, mid + 1, r);
    T[k] = chos(T[k << 1], T[(k << 1) | 1]);
  }
}
void update(int k, int l, int r, int x) {
  if (l == r)
    a[l].r = -1;
  else {
    int mid = (l + r) >> 1;
    if (x <= mid)
      update(k << 1, l, mid, x);
    else
      update((k << 1) | 1, mid + 1, r, x);
    T[k] = chos(T[k << 1], T[(k << 1) | 1]);
  }
}
int query(int k, int l, int r, int x, int y) {
  if ((x <= l) && (r <= y))
    return T[k];
  else {
    int mid = (l + r) >> 1, ans = 0;
    if (x <= mid) ans = chos(ans, query(k << 1, l, mid, x, y));
    if (y > mid) ans = chos(ans, query((k << 1) | 1, mid + 1, r, x, y));
    return ans;
  }
}
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);
  Build_Tree(1, 1, n);
  memset(vis, 0, sizeof(vis));
  cur = 1, pos = 1, a[0].r = -1;
  for (int i = 1; i <= n; ++i) {
    while ((pos <= n) && ((a[pos].l < cur) || (vis[pos]))) ++pos;
    if (pos > n) break;
    k = query(1, 1, n, pos, n);
    vis[k] = 1, update(1, 1, n, k), ++pos, ++cur;
  }
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) v[++vs] = m - a[i].r + 1;
  sort(v + 1, v + vs + 1);
  cur = 1, ans = 0;
  for (int i = 1; i <= vs; ++i)
    if (v[i] >= cur)
      ++cur;
    else
      ++ans;
  printf("%d\n", ans);
  return 0;
}
