#include <bits/stdc++.h>
using namespace std;
int N, M, N_;
pair<int, int> taka[200020];
pair<int, int> seg[800020];
void init() {
  N_ = 1;
  while (N_ < M + 2) N_ *= 2;
  for (int i = 0; i < N * 2 - 1; i++) seg[i] = make_pair(0, 0);
  return;
}
void update_(int k, int l, int r) {
  seg[k].first += seg[k].second;
  seg[k * 2 + 1].second += seg[k].second;
  seg[k * 2 + 2].second += seg[k].second;
  seg[k].second = 0;
  return;
}
int update(int a, int b, int x, int k = 0, int l = 0, int r = N_) {
  if (seg[k].second != 0) update_(k, l, r);
  if (b <= l || r <= a) return 0;
  if (a <= l && r <= b) {
    seg[k].first += x;
    seg[k * 2 + 1].second += x;
    seg[k * 2 + 2].second += x;
    return seg[k].first;
  }
  int res1, res2;
  res1 = update(a, b, x, k * 2 + 1, l, (l + r) / 2);
  res2 = update(a, b, x, k * 2 + 2, (l + r) / 2, r);
  return seg[k].first = max(res1, res2);
}
int getmax(int a, int b, int k = 0, int l = 0, int r = N_) {
  if (seg[k].second != 0) update_(k, l, r);
  if (b <= l || r <= a) return 0;
  if (a <= l && r <= b) return seg[k].first;
  int res1, res2;
  res1 = getmax(a, b, k * 2 + 1, l, (l + r) / 2);
  res2 = getmax(a, b, k * 2 + 2, (l + r) / 2, r);
  return max(res1, res2);
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; i++) scanf("%d%d", &taka[i].first, &taka[i].second);
  int ans = max(0, M - N);
  init();
  sort(taka, taka + N);
  for (int i = 0; i < M + 2; i++) update(i, i + 1, i);
  for (int i = 0; i < N; i++) {
    pair<int, int> now = taka[i];
    update(0, now.second, 1);
    ans = max(ans, getmax(0, N_) - (now.first + M));
  }
  printf("%d\n", ans);
}
