#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();
  ans = max(0, n - m);
  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; });
  cnt = 1;
  s = m + 1;
  for (int i = 0; i <= m; i++) {
    while (cnt <= n && a[cnt].x <= i) s = min(s, a[cnt++].y);
    ans = max(ans, cnt - 1 - (i + m + 1 - s));
  }
  printf("%d\n", ans);
  return 0;
}
