#include <bits/stdc++.h>
using namespace std;
int n, m, f[600000], g[600000], p, q;
pair<int, int> x[200010];
inline void add(int i, int j, int k, int l, int r) {
  if (l <= j && k <= r) {
    f[i]++;
    g[i]++;
  } else {
    f[i << 1] += g[i];
    g[i << 1] += g[i];
    f[i << 1 | 1] += g[i];
    g[i << 1 | 1] += g[i];
    g[i] = 0;
    if (l <= (j + k >> 1)) add(i << 1, j, j + k >> 1, l, r);
    if (r > (j + k >> 1)) add(i << 1 | 1, (j + k >> 1) + 1, k, l, r);
    f[i] = max(f[i << 1], f[i << 1 | 1]);
  }
}
int main() {
  int i;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d%d", &x[i].first, &x[i].second);
  sort(x + 1, x + n + 1);
  for (p = 1; p < m + 1; p <<= 1)
    ;
  for (i = 1; i <= m; i++) f[p + i - 1] = -(m - i + 1);
  for (; i < 2 * p; i++) f[p + i - 1] = -1e9;
  for (i = p - 1; i > 0; i--) f[i] = max(f[i << 1], f[i << 1 | 1]);
  for (i = 1; i <= n; i++) {
    add(1, 1, p, 1, x[i].second);
    q = max(q, f[1] - x[i].first);
  }
  printf("%d\n", q);
  return 0;
}
