#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, m, ans;
vector<int> e[N];
int mv[N << 2], tag[N << 2];
void build(int x, int l, int r) {
  mv[x] = r - m - 1;
  if (l == r) return;
  int mid = (l + r) >> 1, ls = x << 1, rs = ls | 1;
  build(ls, l, mid), build(rs, mid + 1, r);
}
void update(int x, int l, int r, int s, int t) {
  if (l == s && r == t) {
    tag[x]++, mv[x]++;
    return;
  }
  int mid = (l + r) >> 1, ls = x << 1, rs = ls | 1;
  if (t <= mid)
    update(ls, l, mid, s, t);
  else if (s > mid)
    update(rs, mid + 1, r, s, t);
  else
    update(ls, l, mid, s, mid), update(rs, mid + 1, r, mid + 1, t);
  mv[x] = max(mv[ls], mv[rs]) + tag[x];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, l, r; i <= n; i++) scanf("%d%d", &l, &r), e[l].push_back(r);
  build(1, 1, m + 1);
  for (int i = 0; i <= m; i++) {
    for (int v : e[i]) update(1, 1, m + 1, 1, v);
    ans = max(ans, mv[1] - i);
  }
  printf("%d\n", ans);
  return 0;
}
