#include <bits/stdc++.h>
using namespace std;
int n, m, ans = -INT_MAX, w;
int Head[200100], Next[801000], date[801000], tot;
int tree[801000], lazy[801000], l[801000], r[801000], l_[200100], r_[200100];
inline int read() {
  int x = 0;
  char c = getchar();
  while (c > '9' || c < '0') c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x;
}
inline void add(int f, int w) {
  date[++tot] = w, Next[tot] = Head[f], Head[f] = tot;
}
inline void upmax(int &a, int b) {
  if (b > a) a = b;
}
void pre() {
  n = read(), m = read();
  for (register int i = 1; i <= n; i++)
    l_[i] = read(), r_[i] = read(), add(r_[i], i);
}
inline void pushdown(int x) {
  if (lazy[x]) {
    int ll = x * 2, rr = ll + 1;
    lazy[ll] += lazy[x], lazy[rr] += lazy[x];
    tree[ll] += lazy[x], tree[rr] += lazy[x];
    lazy[x] = 0;
  }
}
inline void update(int x) { tree[x] = max(tree[x * 2], tree[x * 2 + 1]); }
void build(int x, int ll, int rr) {
  l[x] = ll, r[x] = rr;
  if (ll == rr) {
    tree[x] = -ll + 1;
    return;
  }
  int mid = (ll + rr) >> 1;
  build(x * 2, ll, mid);
  build(x * 2 + 1, mid + 1, rr);
  update(x);
}
void change(int x, int ll, int rr) {
  pushdown(x);
  if (l[x] == ll && r[x] == rr) {
    lazy[x] += w, tree[x] += w;
    return;
  }
  int mid = (l[x] + r[x]) >> 1;
  if (rr <= mid)
    change(x * 2, ll, rr);
  else if (ll > mid)
    change(x * 2 + 1, ll, rr);
  else {
    change(x * 2, ll, mid);
    change(x * 2 + 1, mid + 1, rr);
  }
  update(x);
}
void find(int x, int ll, int rr) {
  pushdown(x);
  if (l[x] == ll && r[x] == rr) {
    upmax(ans, tree[x]);
    return;
  }
  int mid = (l[x] + r[x]) >> 1;
  if (rr <= mid)
    find(x * 2, ll, rr);
  else if (ll > mid)
    find(x * 2 + 1, ll, rr);
  else
    find(x * 2, ll, mid), find(x * 2 + 1, mid + 1, rr);
}
void work() {
  int now;
  ans = n - m;
  for (register int i = Head[m + 1]; i; i = Next[i]) {
    now = date[i], w = 1;
    change(1, l_[now] + 1, m + 1);
  }
  upmax(ans, tree[1]);
  for (register int i = m; i; --i) {
    w = -1;
    change(1, 1, i + 1);
    for (register int j = Head[i]; j; j = Next[j]) {
      now = date[j], w = 1;
      change(1, l_[now] + 1, i + 1);
    }
    find(1, 1, i + 1);
  }
  printf("%d\n", ans);
}
int main() {
  pre();
  build(1, 1, m + 1);
  work();
  return 0;
}
