#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)(1e5) + 5;
int mx[maxn], su[maxn];
vector<int> nxt[maxn];
int n, m;
inline void addX(int x, int v) {
  mx[x] += v;
  su[x] += v;
}
inline void pd(int x) {
  if (su[x]) {
    addX(x << 1, su[x]);
    addX(x << 1 | 1, su[x]);
    su[x] = 0;
  }
}
inline void pu(int x) { mx[x] = max(mx[x << 1], mx[x << 1 | 1]); }
int Q(int x, int l, int r, int p) {
  if (r <= p) return mx[x];
  pd(x);
  int mid = (l + r) >> 1, ret = Q(x << 1, l, mid, p);
  if (mid < p) ret = max(ret, Q(x << 1 | 1, mid + 1, r, p));
  return ret;
}
void M(int x, int l, int r, int p, int v) {
  if (p <= l) {
    addX(x, v);
    return;
  }
  pd(x);
  int mid = (l + r) >> 1;
  if (p <= mid) M(x << 1, l, mid, p, v);
  M(x << 1 | 1, mid + 1, r, p, v);
  pu(x);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    nxt[l].push_back(m - r + 1);
  }
  int ret = max(0, n - m);
  for (int i = 1; i <= m; ++i) M(1, 0, m, i, -1);
  for (int i = 0; i <= m; ++i) {
    for (int j = 0; j < (int)nxt[i].size(); ++j) M(1, 0, m, nxt[i][j], 1);
    ret = max(ret, Q(1, 0, m, m - i) - i);
  }
  return printf("%d\n", ret), 0;
}
