#include <bits/stdc++.h>
using namespace std;
const int N = 200010, M = 200010, INF = 0x3f3f3f3f;
template <class T>
void read(T &x) {
  x = 0;
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) x = x * 10 + c - 48, c = getchar();
}
inline void file() {}
struct Segment_tree {
  long long Sum[N << 2], Add[N << 2], Max[N << 2];
  inline void Pushup(int h) {
    Sum[h] = Sum[h << 1] + Sum[h << 1 | 1];
    Max[h] = max(Max[h << 1], Max[h << 1 | 1]);
  }
  inline void Pushdown(int h, int l, int r) {
    if (Add[h]) {
      Sum[h << 1] += Add[h] * (((l + r) >> 1) - l + 1),
          Sum[h << 1 | 1] += Add[h] * (r - ((l + r) >> 1));
      Add[h << 1] += Add[h], Add[h << 1 | 1] += Add[h];
      Max[h << 1] += Add[h], Max[h << 1 | 1] += Add[h];
      Add[h] = 0;
    }
  }
  void Build(int h, int l, int r, int n) {
    if (l == r) return void(Max[h] = Sum[h] = -(n - l + 1));
    Build(h << 1, l, ((l + r) >> 1), n),
        Build(h << 1 | 1, ((l + r) >> 1) + 1, r, n);
    Pushup(h);
  }
  void Modify(int h, int l, int r, int L, int R) {
    if (L <= l && r <= R) {
      Add[h] += 1, Sum[h] += r - l + 1, Max[h] += 1;
      return;
    }
    Pushdown(h, l, r);
    if (L <= ((l + r) >> 1)) Modify(h << 1, l, ((l + r) >> 1), L, R);
    if (R > ((l + r) >> 1)) Modify(h << 1 | 1, ((l + r) >> 1) + 1, r, L, R);
    Pushup(h);
  }
} t;
struct node {
  int x, y;
  bool operator<(const node &r) const { return x < r.x; }
} P[N];
int n, m;
void init() {
  read(n), read(m);
  for (int i = 1; i <= n; ++i) read(P[i].x), read(P[i].y);
  sort(P + 1, P + n + 1);
}
void solve() {
  long long ans = 0;
  t.Build(1, 1, m + 1, m);
  for (int i = 1; i <= n; ++i)
    t.Modify(1, 1, m + 1, 1, P[i].y), ans = max(ans, t.Max[1] - P[i].x);
  printf("%lld\n", ans);
}
int main() {
  init();
  solve();
  return 0;
}
