#include <bits/stdc++.h>
using namespace std;
int N, M, L[201010], R[201000];
int Max[2010000], tag[2010000];
vector<int> vec[1010000];
inline void Pushdown(int now) {
  if (tag[now]) {
    Max[now << 1] += tag[now];
    Max[now << 1 | 1] += tag[now];
    tag[now << 1] += tag[now];
    tag[now << 1 | 1] += tag[now];
    tag[now] = 0;
    return;
  }
}
inline void Update(int now) {
  Max[now] = max(Max[now << 1], Max[now << 1 | 1]);
}
inline void Build(int now, int l, int r) {
  if (l == r) {
    Max[now] = -l;
    return;
  }
  int mid = (l + r) >> 1;
  Build(now << 1, l, mid);
  Build(now << 1 | 1, mid + 1, r);
  Update(now);
}
inline void Modify(int now, int l, int r, int x, int y, int d) {
  x = max(0, x);
  y = min(M, y);
  if (x <= l && r <= y) {
    tag[now] += d;
    Max[now] += d;
    return;
  }
  int mid = (l + r) >> 1;
  Pushdown(now);
  if (x <= mid) Modify(now << 1, l, mid, x, y, d);
  if (y > mid) Modify(now << 1 | 1, mid + 1, r, x, y, d);
  Update(now);
}
inline int Qry(int now, int l, int r, int x, int y) {
  x = max(0, x);
  y = min(M, y);
  if (x <= l && r <= y) return Max[now];
  int res = 0, mid = (l + r) >> 1;
  Pushdown(now);
  if (x <= mid) res = max(res, Qry(now << 1, l, mid, x, y));
  if (y > mid) res = max(res, Qry(now << 1 | 1, mid + 1, r, x, y));
  Update(now);
  return res;
}
int main() {
  cin >> N >> M;
  for (register int i = 1; i <= N; ++i)
    cin >> L[i] >> R[i], vec[R[i]].push_back(L[i]);
  Build(1, 0, M);
  int ans = 0;
  for (register int i = M + 1; i >= 1; --i) {
    int SZ = vec[i].size();
    if (i <= M && i >= 1) {
      Modify(1, 0, M, 0, M, -1);
    }
    for (register int j = 0; j < SZ; ++j) {
      int l = vec[i][j];
      Modify(1, 0, M, l, M, 1);
    }
    ans = max(ans, Qry(1, 0, M, 0, i - 1));
  }
  cout << ans << endl;
  return 0;
}
