#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f * x;
}
int n, m;
struct P {
  int x, y;
} a[200005];
int ans, s, cnt;
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; i++) a[i].x = read(), a[i].y = read();
  sort(a + 1, a + 1 + n,
       [](P a, P b) { return a.x < b.x || (a.x == b.x && a.y > b.y); });
  cnt = m + 1;
  for (int i = 1; i <= n; i++)
    cnt = min(cnt, a[i].y), ans = max(ans, i - (a[i].x + m + 1 - cnt));
  printf("%d\n", ans);
  return 0;
}
