#include <bits/stdc++.h>
const int maxn = 200005;
const int maxno = maxn << 2;
int maxv[maxno], addv[maxno];
void maintain(int o) { maxv[o] = std::max(maxv[o << 1], maxv[o << 1 | 1]); }
void paint(int o, int v) {
  maxv[o] += v;
  addv[o] += v;
}
void pushdown(int o) {
  if (addv[o] != 0) {
    paint(o << 1, addv[o]);
    paint(o << 1 | 1, addv[o]);
    addv[o] = 0;
  }
}
void build_tree(int o, int L, int R) {
  addv[o] = 0;
  if (L == R) {
    maxv[o] = -L + 1;
  } else {
    int M = (L + R) / 2;
    build_tree(o << 1, L, M);
    build_tree(o << 1 | 1, M + 1, R);
    maintain(o);
  }
}
void update(int o, int L, int R, const int &ql, const int &qr, const int &v) {
  if (ql <= L && R <= qr) {
    paint(o, v);
  } else {
    int M = (L + R) / 2;
    pushdown(o);
    if (ql <= M) update(o << 1, L, M, ql, qr, v);
    if (qr > M) update(o << 1 | 1, M + 1, R, ql, qr, v);
    maintain(o);
  }
}
std::vector<int> V[maxn];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  build_tree(1, 1, m + 1);
  for (int i = 1; i <= n; i++) {
    int L, R;
    scanf("%d%d", &L, &R);
    V[R].push_back(L);
  }
  int ans = -0x7fffffff;
  for (int i = m + 1; i >= 1; i--) {
    int bs = -(m - i + 1);
    for (int l : V[i]) {
      update(1, 1, m + 1, l + 1, m + 1, 1);
    }
    bs += maxv[1];
    ans = std::max(ans, bs);
  }
  printf("%d\n", ans);
  return 0;
}
