#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T& num) {
  num = 0;
  T f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') num = num * 10 + ch - '0', ch = getchar();
  num *= f;
}
inline int getgcd(int x, int y) {
  if (!x) return y;
  return getgcd(y % x, x);
}
inline int power(int x, int k, int p) {
  int res = 1;
  for (; k; k >>= 1, x = (long long)x * x % p)
    if (k & 1) res = (long long)res * x % p;
  return res;
}
const double pi = acos(-1);
inline void judge() { freopen("input.txt", "r", stdin); }
const int maxn = 2e5 + 5;
int n, m, ans;
pair<int, int> p[maxn];
int maxi[maxn << 2], tag[maxn << 2];
void U(int x) { maxi[x] = max(maxi[(x << 1)], maxi[(x << 1 | 1)]); }
void B(int x, int l, int r) {
  if (l == r) {
    maxi[x] = l;
    return;
  }
  B((x << 1), l, ((l + r) >> 1));
  B((x << 1 | 1), ((l + r) >> 1) + 1, r);
  U(x);
}
void M(int x, int num) {
  tag[x] += num;
  maxi[x] += num;
}
void PD(int x) {
  M((x << 1), tag[x]);
  M((x << 1 | 1), tag[x]);
  tag[x] = 0;
}
void M(int x, int l, int r, int long long, int rr) {
  if (l == long long&& r == rr) {
    M(x, 1);
    return;
  }
  PD(x);
  if (rr <= ((l + r) >> 1))
    M((x << 1), l, ((l + r) >> 1), long long, rr);
  else if (long long > ((l + r) >> 1))
    M((x << 1 | 1), ((l + r) >> 1) + 1, r, long long, rr);
  else
    M((x << 1), l, ((l + r) >> 1), long long, ((l + r) >> 1)),
        M((x << 1 | 1), ((l + r) >> 1) + 1, r, ((l + r) >> 1) + 1, rr);
  U(x);
}
int main() {
  read(n);
  read(m);
  for (int(i) = (1); (i) <= (n); (i)++) read(p[i].first), read(p[i].second);
  sort(p + 1, p + n + 1);
  B(1, 0, m + 1);
  for (int(i) = (1); (i) <= (n); (i)++) {
    int s = p[i].first;
    M(1, 0, m + 1, 0, p[i].second);
    ans = max(ans, maxi[1] - (m + 1 + s));
  }
  printf("%d\n", ans);
  return 0;
}
