#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];
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);
  int res = N;
  for (int c = 0; c < (2); ++c) {
    for (int i = 0; i < (N); ++i) {
      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 - max(t[nind].second, st + 1), nind));
        ind--;
      }
      if (!S.empty()) {
        auto p = *S.begin();
        S.erase(p);
        done[p.second] = 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++;
    while (st <= M && st < t1[0].first) st++;
    ind = 0;
    for (int i = (st); i <= (M); ++i) {
      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 sum = 0;
    for (int i = 0; i < (N); ++i) sum += !done[i];
    res = min(res, sum);
    memset(s, 0, sizeof(s));
    memset(done, 0, sizeof(done));
    for (int i = 0; i < (N); ++i)
      t[i] = make_pair(M + 1 - t[i].second, M + 1 - t[i].first);
  }
  printf("%d\n", res);
  return 0;
}
