#include <bits/stdc++.h>
using namespace std;
const int INF = 0x2aaaaaaa;
const long long INFLL = 0x1f1f1f1f1f1f1f1fLL;
template <class A, class B>
inline ostream& operator<<(ostream& st, const pair<A, B>& P) {
  return st << "(" << P.first << "," << P.second << ")";
};
template <class A, class B>
inline pair<A, B> operator+(const pair<A, B>& P, const pair<A, B>& Q) {
  return pair<A, B>(P.first + Q.first, P.second + Q.second);
};
template <class A, class B>
inline pair<A, B> operator-(const pair<A, B>& P, const pair<A, B>& Q) {
  return pair<A, B>(P.first - Q.first, P.second - Q.second);
};
pair<int, int> lr[300000];
bool f[300002];
bool fi[300002];
pair<int, int> ri[300000];
int main() {
  memset(f, 0, sizeof(f));
  memset(fi, 0, sizeof(fi));
  int N, M;
  scanf("%d %d", &N, &M);
  for (int i = 0; i < N; i++) {
    int L, R;
    scanf("%d %d", &L, &R);
    lr[i] = {L, -R};
  }
  sort(lr, lr + N);
  for (int i = 0; i < N; i++) {
    ri[i] = {-lr[i].second, i};
  }
  sort(ri, ri + N);
  priority_queue<int, vector<int>, greater<int>> Q;
  int j = 0;
  int cnt = 0;
  for (int i = 1; i <= M; i++) {
    for (; j < N; ++j) {
      if (ri[j].first == i) {
        Q.push(ri[j].second);
      } else
        break;
    }
    if (Q.empty()) continue;
    int k = Q.top();
    Q.pop();
    f[i] = true;
    fi[k] = true;
    cnt++;
  }
  j = 1;
  for (int i = 0; i < N; i++) {
    if (fi[i]) continue;
    if (lr[i].first < j) continue;
    for (; j < M; ++j) {
      if (f[j] == false) break;
    }
    if (j == N) break;
    cnt++;
    j++;
  }
  printf("%d\n", (int)(N - cnt));
  ;
}
