#include <bits/stdc++.h>
using namespace std;
int n, m;
pair<int, int> ps[666666];
int M = 262144, M2 = M + M, ls[666666], rs[666666];
int mi[666666], tag[666666];
void build() {
  for (int i = M + 1; i <= M + M; i++) ls[i] = rs[i] = i - M;
  for (int i = M - 1; i; i--)
    ls[i] = ls[i + i], rs[i] = rs[i + i + 1],
    mi[i] = min(mi[i + i], mi[i + i + 1]);
}
void pd(int x) {
  if (tag[x]) {
    mi[x] += tag[x];
    if (x + x <= M2) tag[x + x] += tag[x], tag[x + x + 1] += tag[x];
    tag[x] = 0;
  }
}
void upd(int x) {
  pd(x + x);
  pd(x + x + 1);
  mi[x] = min(mi[x + x], mi[x + x + 1]);
}
void edit(int x, int ql, int qr, int v) {
  if (x > M2 || ql > qr) return;
  pd(x);
  if (ql == ls[x] && qr == rs[x]) {
    tag[x] += v;
    return;
  }
  int mid = ls[x] + rs[x] >> 1;
  edit(x + x, ql, min(qr, mid), v);
  edit(x + x + 1, max(mid + 1, ql), qr, v);
  upd(x);
}
int qmin(int x, int ql, int qr) {
  if (x > M2 || ql > qr) return 1e9;
  pd(x);
  if (ql == ls[x] && qr == rs[x]) return mi[x];
  int mid = ls[x] + rs[x] >> 1;
  int ans =
      min(qmin(x + x, ql, min(qr, mid)), qmin(x + x + 1, max(mid + 1, ql), qr));
  upd(x);
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    l = max(l, 1);
    r = min(r, m);
    ps[i].first = l;
    ps[i].second = r;
  }
  sort(ps + 1, ps + 1 + n);
  memset(mi, 127 / 3, sizeof mi);
  for (int i = 1; i <= m + 1; i++) mi[i + M] = m - i + 1;
  build();
  int ans = n;
  for (int i = 1; i <= n; i++) {
    edit(1, ps[i].second + 1, m + 1, 1);
    ans = min(ans, n - i + ps[i].first + qmin(1, 1, m + 1));
  }
  printf("%d\n", n - ans);
}
