#include <bits/stdc++.h>
using namespace std;
struct ss {
  int l, r;
  bool operator<(const ss& c) const {
    if (l != c.l) return l < c.l;
    return r > c.r;
  }
} ba[202020];
int N, M, ls[202020], lmx, dap;
int j2, cnt[602020], mxs[602020], mxx[602020], cc, rmx;
void add(int dep, int ix, int s, int e, int v, int& mx, int& mix) {
  int gop = j2 / (1 << dep);
  if (s <= ix * gop && (ix + 1) * gop - 1 <= e) {
    cnt[ix] += v, mxs[ix] += v;
    if (mx < mxs[ix]) mx = mxs[ix], mix = mxx[ix];
    return;
  }
  if (e < ix * gop || s >= (ix + 1) * gop) return;
  add(dep + 1, ix * 2, s, e, v, mx, mix);
  add(dep + 1, ix * 2 + 1, s, e, v, mx, mix);
  if (mxs[ix * 2] > mxs[ix * 2 + 1])
    mxs[ix] = mxs[ix * 2], mxx[ix] = mxx[ix * 2];
  else
    mxs[ix] = mxs[ix * 2 + 1], mxx[ix] = mxx[ix * 2 + 1];
  mxs[ix] += cnt[ix];
  if (mx < mxs[ix]) mx = mxs[ix], mix = mxx[ix];
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; i++) {
    int s, e;
    scanf("%d%d", &s, &e);
    ba[i].l = s, ba[i].r = M + 1 - e;
    ls[i] = s;
  }
  sort(ls, ls + N), sort(ba, ba + N);
  for (int i = 0; i < N; i++) {
    if (ls[i] >= lmx + 1) lmx++;
  }
  dap = lmx;
  for (j2 = 1; j2 <= M; j2 <<= 1)
    ;
  int t1, t2;
  for (int i = j2; i < 2 * j2; i++) mxx[i] = i;
  for (int i = 1; i <= M; i++) add(0, 1, i + j2, i + j2, -i, t1, t2);
  add(0, 1, M + 1 + j2, j2 * 2 - 1, -1000000, t1, t2);
  for (int i = 0; i < N; i++) {
    int g = ba[i].r;
    if (dap < min(N - i, lmx) + rmx) dap = min(N - i, lmx) + rmx;
    if (g <= cc) continue;
    rmx++;
    int mx = -1000000, mix;
    add(0, 1, g + j2, M + j2, 1, mx, mix);
    mix -= j2;
    if (mx == 0) cc = mix;
    if (dap < min(N - i, lmx) + rmx) dap = min(N - i - 1, lmx) + rmx;
  }
  if (dap > M) dap = M;
  printf("%d", max(N - dap, 0));
  return 0;
}
