#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
struct Pos {
  int x, y;
} p[N];
bool cmp(const Pos &a, const Pos &b) {
  return a.x == b.x ? a.y > b.y : a.x < b.x;
}
int mx[N << 2], sum[N << 2];
void updata(int x, int l, int r, int d, int w) {
  if (l == r) {
    mx[x] += w, sum[x] += w;
    return;
  }
  int mid = (l + r) >> 1;
  if (d <= mid)
    updata(x << 1, l, mid, d, w);
  else
    updata(x << 1 | 1, mid + 1, r, d, w);
  mx[x] = max(mx[x << 1 | 1], mx[x << 1] + sum[x << 1 | 1]);
  sum[x] = sum[x << 1] + sum[x << 1 | 1];
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, m, ans = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> p[i].x >> p[i].y;
  sort(p + 1, p + 1 + n, cmp);
  for (int i = 1; i <= m; i++) updata(1, 0, m + 1, i, -1);
  for (int i = 1; i <= n; i++) {
    updata(1, 0, m + 1, p[i].y, 1);
    ans = max(ans, -p[i].x + mx[1]);
  }
  cout << ans << endl;
  return 0;
}
