#include <bits/stdc++.h>
using namespace std;
const double pi =
    3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int MR = 2e5 + 10;
pair<int, int> t[MR], t1[MR];
int s[MR];
int done[MR], suf[MR];
bool taken[MR];
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  for (int i = 0; i < (N); ++i) {
    scanf("%d%d", &t[i].first, &t[i].second);
    s[0]++;
    s[t[i].first + 1]--;
    s[t[i].second]++;
    s[M + 1]--;
    t1[i].first = t[i].first;
    t1[i].second = i;
  }
  int st = 1;
  for (int i = (1); i <= (M); ++i) {
    s[i] += s[i - 1];
    if (s[i] < s[st] && s[i] > 0) st = i;
  }
  sort(t1, t1 + N);
  set<pair<int, int>> S;
  while (st > t1[N - 1].first) st--;
  int ind = N - 1;
  for (int i = (st + 1) - 1; i >= (1); --i) {
    while (ind >= 0 && t1[ind].first >= i) {
      int nind = t1[ind].second;
      S.insert(make_pair(M + 1 - t[nind].second - suf[t[nind].second], nind));
      ind--;
    }
    if (!S.empty()) {
      auto p = *S.begin();
      S.erase(p);
      done[p.second] = i;
      taken[i] = 1;
    }
    suf[i] = suf[i + 1] + taken[i];
  }
  int cnt = 0;
  for (int i = 0; i < (N); ++i)
    if (!done[i]) {
      t1[cnt].first = t[i].second;
      t1[cnt].second = i;
      cnt++;
    }
  if (!cnt) {
    printf("0\n");
    return 0;
  }
  sort(t1, t1 + cnt);
  S.clear();
  st = 0;
  while (st <= M && st < t1[0].first) st++;
  ind = 0;
  for (int i = (st); i <= (M); ++i) {
    if (taken[i]) continue;
    while (ind < cnt && t1[ind].first <= i) S.insert(t1[ind++]);
    if (!S.empty()) {
      auto p = *S.begin();
      S.erase(p);
      done[p.second] = i;
    }
  }
  int res = 0;
  for (int i = 0; i < (N); ++i) res += !done[i];
  printf("%d\n", res);
  return 0;
}
