#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long xx = 0, flagg = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') {
    flagg = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    xx = xx * 10 + ch - '0';
    ch = getchar();
  }
  return xx * flagg;
}
void pus(long long xx, long long flagg) {
  if (xx < 0) {
    putchar('-');
    xx = -xx;
  }
  if (xx >= 10) pus(xx / 10, 0);
  putchar(xx % 10 + '0');
  if (flagg == 1) putchar(' ');
  if (flagg == 2) putchar('\n');
  return;
}
int n, m, i, x, y, ans;
struct nyh {
  int l, r;
} o[200005];
bool cmp(nyh u, nyh v) { return u.l < v.l || u.l == v.l && u.r < v.r; }
set<int> s;
set<int>::iterator it;
set<pair<int, int> > t;
set<pair<int, int> >::iterator it2;
int main() {
  n = read();
  m = read();
  for (i = 0; i <= m; i++) s.insert(i);
  s.insert(1000000000);
  for (i = 1; i <= n; i++) {
    o[i].l = read();
    o[i].r = read();
  }
  sort(o + 1, o + n + 1, cmp);
  for (i = 1; i <= n; i++) {
    t.insert(make_pair(o[i].r, i));
    it = s.lower_bound(1);
    if ((*it) <= o[i].l) {
      s.erase(it);
    } else {
      while (t.size() != 0) {
        it2 = t.end();
        it2--;
        it = s.lower_bound(it2->first);
        if ((*it) == 1000000000)
          t.erase(it2);
        else {
          t.erase(it2);
          s.erase(it);
          break;
        }
      }
      if (t.size() == 0) ans++;
    }
  }
  pus(ans, 2);
  return 0;
}
