#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, _x, cnt, ans;
struct P {
  int x, y;
} a[200005];
struct node {
  int x, y, s, tag;
  node *l, *r;
  node(int x, int y, node *l = 0, node *r = 0)
      : x(x), y(y), l(l), r(r), s(0), tag(0) {
    if (l)
      upd();
    else
      s = x - m - 1;
  }
  void upd() { s = max(l->s, r->s); }
  void push() {
    if (tag) {
      l->s += tag;
      l->tag += tag;
      r->s += tag;
      r->tag += tag;
      tag = 0;
    }
  }
  void mod() {
    if (_x >= y) {
      s++;
      tag++;
      return;
    }
    push();
    if (_x > (x + y >> 1)) r->mod();
    l->mod();
    upd();
  }
} * root;
node *build(int x, int y) {
  return x == y ? new node(x, y)
                : new node(x, y, build(x, (x + y >> 1)),
                           build((x + y >> 1) + 1, y));
}
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; });
  root = build(1, m + 1);
  cnt = 1;
  for (int i = 0; i <= m; i++) {
    while (cnt <= n && a[cnt].x == i) {
      _x = a[cnt++].y;
      root->mod();
    }
    ans = max(ans, root->s - i);
  }
  printf("%d\n", ans);
  return 0;
}
