#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int n, m, ans = 0;
struct Opt {
  int l, r;
} p[maxn];
struct Node {
  int sum, lazy;
} node[maxn * 4];
bool cmp(const Opt &A, const Opt &B) {
  if (A.r != B.r) return A.r > B.r;
  return A.l < B.l;
}
void pushdown(int now, int nl, int nr) {
  if (!node[now].lazy) return;
  int mid = (nl + nr) / 2;
  node[now].lazy = 0;
  node[(now * 2)].lazy = node[(now * 2 + 1)].lazy = 1;
  node[(now * 2)].sum = (mid - nl + 1);
  node[(now * 2 + 1)].sum = (nr - mid);
  return;
}
void update(int now) {
  node[now].sum = node[(now * 2)].sum + node[(now * 2 + 1)].sum;
}
void add(int now, int nl, int nr, int ql, int qr) {
  if (ql <= nl && nr <= qr) {
    node[now].sum = (nr - nl + 1);
    node[now].lazy = 1;
    return;
  }
  if (nr < ql || qr < nl) return;
  int mid = (nl + nr) / 2;
  pushdown(now, nl, nr);
  add((now * 2), nl, mid, ql, qr);
  add((now * 2 + 1), mid + 1, nr, ql, qr);
  update(now);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &p[i].l, &p[i].r);
  }
  sort(p + 1, p + n + 1, cmp);
  for (int i = 1; i <= n; i++) {
    if (p[i].l != 0) add(1, 1, m, 1, p[i].l);
    if (p[i].r != m + 1) add(1, 1, m, p[i].r, m);
    ans = max(ans, i - node[1].sum);
  }
  printf("%d\n", ans);
  return 0;
}
