#include <bits/stdc++.h>
using namespace std;
int n, m;
const int maxn = 2e5 + 100;
pair<int, int> a[maxn];
int tree[maxn << 2], lazy[maxn << 2];
inline void pushup(int cur) {
  tree[cur] = max(tree[cur << 1], tree[cur << 1 | 1]);
}
inline void push(int cur, int v) {
  tree[cur] += v;
  lazy[cur] += v;
}
inline void pushdown(int cur) {
  if (lazy[cur]) {
    push(cur << 1, lazy[cur]);
    push(cur << 1 | 1, lazy[cur]);
    lazy[cur] = 0;
  }
}
void build(int cur, int tl, int tr) {
  lazy[cur] = 0;
  if (tl == tr) {
    tree[cur] = -(m - tl + 1);
  } else {
    int tm = (tl + tr) >> 1;
    build(cur << 1, tl, tm);
    build(cur << 1 | 1, tm + 1, tr);
    pushup(cur);
  }
}
void update(int cur, int tl, int tr, int ql, int qr, int v) {
  if (ql > qr)
    return;
  else if (ql <= tl && tr <= qr)
    push(cur, v);
  else {
    pushdown(cur);
    int tm = (tl + tr) >> 1;
    update(cur << 1, tl, tm, ql, min(tm, qr), v);
    update(cur << 1 | 1, tm + 1, tr, max(tm + 1, ql), qr, v);
    pushup(cur);
  }
}
int query(int cur, int tl, int tr, int ql, int qr) {
  if (ql > qr)
    return -1e9;
  else if (ql <= tl && tr <= qr)
    return tree[cur];
  else {
    pushdown(cur);
    int tm = (tl + tr) >> 1;
    int ret = query(cur << 1, tl, tm, ql, min(tm, qr));
    ret = max(ret, query(cur << 1 | 1, tm + 1, tr, max(tm + 1, ql), qr));
    pushup(cur);
    return ret;
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%d %d", &a[i].first, &a[i].second);
  }
  sort(a, a + n);
  int ans = max(0, n - m);
  build(1, 0, m + 1);
  for (int i = 0; i < n; ++i) {
    update(1, 0, m + 1, a[i].first + 1, a[i].second, 1);
    int ret;
    ans = max(ans, ret = query(1, 0, m + 1, a[i].first + 1, m) - a[i].first);
  }
  printf("%d\n", ans);
}
