#include <bits/stdc++.h>
using namespace std;
const int Maxn = 200010;
const int inf = 2147483647;
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 << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return x * f;
}
int n, m;
struct Node {
  int l, r;
} a[Maxn];
bool cmp(Node a, Node b) { return a.r > b.r; }
struct Seg {
  int l, r, lc, rc, mx, tag;
} tr[Maxn << 1];
int tot = 0;
void work(int x, int y) {
  tr[x].mx += y;
  tr[x].tag += y;
}
void up(int x) {
  int lc = tr[x].lc, rc = tr[x].rc;
  tr[x].mx = max(tr[lc].mx, tr[rc].mx);
}
void down(int x) {
  if (tr[x].tag) {
    int t = tr[x].tag;
    work(tr[x].lc, t);
    work(tr[x].rc, t);
    tr[x].tag = 0;
  }
}
void build(int l, int r) {
  int t = ++tot;
  tr[t].l = l;
  tr[t].r = r;
  tr[t].tag = 0;
  if (l == r) {
    tr[t].mx = -l;
    return;
  }
  int mid = l + r >> 1;
  tr[t].lc = tot + 1;
  build(l, mid);
  tr[t].rc = tot + 1;
  build(mid + 1, r);
  up(t);
}
void add(int x, int l, int r) {
  if (tr[x].l == l && tr[x].r == r) {
    work(x, 1);
    return;
  }
  int lc = tr[x].lc, rc = tr[x].rc, mid = tr[x].l + tr[x].r >> 1;
  down(x);
  if (r <= mid)
    add(lc, l, r);
  else if (l > mid)
    add(rc, l, r);
  else
    add(lc, l, mid), add(rc, mid + 1, r);
  up(x);
}
int query(int x, int l, int r) {
  if (tr[x].l == l && tr[x].r == r) return tr[x].mx;
  int lc = tr[x].lc, rc = tr[x].rc, mid = tr[x].l + tr[x].r >> 1;
  down(x);
  int re;
  if (r <= mid)
    re = query(lc, l, r);
  else if (l > mid)
    re = query(rc, l, r);
  else
    re = max(query(lc, l, mid), query(rc, mid + 1, r));
  up(x);
  return re;
}
int main() {
  n = read(), m = read();
  build(0, m + 1);
  for (int i = 1; i <= n; i++) a[i].l = read(), a[i].r = read();
  sort(a + 1, a + 1 + n, cmp);
  int ans = n - m;
  for (int i = 1; i <= n; i++) {
    if (i == 1 || a[i].r == a[i - 1].r)
      add(1, a[i].l, m + 1);
    else {
      int t = query(1, 0, a[i - 1].r - 1) - (m - a[i - 1].r + 1);
      ans = max(ans, t);
      add(1, a[i].l, m + 1);
    }
  }
  int t = query(1, 0, a[n].r - 1) - (m - a[n].r + 1);
  ans = max(ans, t);
  printf("%d", ans);
}
