#include <bits/stdc++.h>
using namespace std;
const int MAXN = 400000 + 10;
int N, M;
int L[MAXN], R[MAXN];
int In[MAXN], Out[MAXN];
bool Cmpin(const int& a, const int& b) { return L[a] < L[b]; }
bool Cmpout(const int& a, const int& b) { return R[a] < R[b]; }
set<pair<int, int> > Set;
int Used[MAXN * 2];
void Work() {
  scanf("%d%d", &N, &M);
  int n = 0;
  int Ans = 0;
  for (int i = 0; i < N; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    if (l == 0 && r == M + 1)
      Ans++;
    else {
      L[n] = r;
      R[n] = l + M;
      In[n] = n;
      Out[n] = n;
      n++;
    }
  }
  N = n;
  sort(In, In + N, Cmpin);
  sort(Out, Out + N, Cmpout);
  int idin = 0, idout = 0;
  for (int m = 0; m <= M + M + 1; m++) {
    while (idin < N && L[In[idin]] == m) {
      Set.insert(make_pair(R[In[idin]], In[idin]));
      idin++;
    }
    if (!Set.empty()) {
      int kt = m;
      if (kt > M) kt -= M;
      if (!Used[kt]) {
        auto x = Set.begin();
        Set.erase(x);
        Used[kt] = 1;
      }
    }
    while (idout < N && R[Out[idout]] == m) {
      auto x = Set.find(make_pair(R[Out[idout]], Out[idout]));
      if (x != Set.end()) {
        Set.erase(x);
        Ans++;
      }
      idout++;
    }
  }
  printf("%d\n", Ans);
}
int main() {
  Work();
  return 0;
}
