#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
using namespace std;
const int N = 200000 + 10;
const long long MOD = 1000000000 + 7;
const long long INF = 1000000010;
const long long LOG = 25;
int n, seg[N << 2], lazy[N << 2], L[N], R[N], m, num[N];
vector<int> vl[N];
void modify(int id, int x) {
  seg[id] += x;
  lazy[id] += x;
}
void shift(int id) {
  modify(id << 1, lazy[id]);
  modify(id << 1 | 1, lazy[id]);
  lazy[id] = 0;
}
void add(int id, int lq, int rq, int x, int l, int r) {
  if (rq <= l || r <= lq) return;
  if (lq <= l && r <= rq) {
    modify(id, x);
    return;
  }
  int md = (l + r) >> 1;
  shift(id);
  add(id << 1, lq, rq, x, l, md);
  add(id << 1 | 1, lq, rq, x, md, r);
  seg[id] = max(seg[id << 1], seg[id << 1 | 1]);
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> m >> n;
  for (int i = 1; i <= m; i++) {
    cin >> L[i] >> R[i];
    vl[L[i]].push_back(R[i]);
  }
  int mx = 0, mx2 = 0;
  for (int i = 1; i <= n + 1; i++)
    add(1, i, i + 1, -(n - i + 1), 1, n + 2), num[i] = -(n - i + 1);
  for (int i = 0; i <= n; i++) {
    for (auto u : vl[i]) {
      add(1, 1, u + 1, 1, 1, n + 2);
      for (int j = 1; j <= u; j++) num[j]++;
    }
    for (int j = 1; j <= n + 1; j++) mx2 = max(mx2, num[j] - i);
    mx = max(mx, seg[1] - i);
  }
  cout << mx2;
  return 0;
}
