#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());
const int N = (int)2e5 + 9;
struct Node {
  pair<int, int> value;
  int lazy;
};
Node Tree[N * 4 + 123];
const int inf = (int)1e9;
void build(int node, int cl, int cr) {
  Tree[node].lazy = 0;
  if (cl == cr) {
    Tree[node].value = make_pair(0, cl);
    return;
  }
  int mid = (cl + cr) / 2;
  build(node * 2, cl, mid);
  build(node * 2 + 1, mid + 1, cr);
}
void push(int node, int cl, int cr) {
  Tree[node].value.first += Tree[node].lazy;
  if (cl != cr) {
    Tree[node * 2].lazy += Tree[node].lazy;
    Tree[node * 2 + 1].lazy += Tree[node].lazy;
  }
  Tree[node].lazy = 0;
}
void update(int node, int cl, int cr, int tl, int tr, int vl) {
  push(node, cl, cr);
  if (cr < tl) return;
  if (cl > tr) return;
  if (cl >= tl && cr <= tr) {
    Tree[node].lazy = vl;
    push(node, cl, cr);
    return;
  }
  int mid = (cl + cr) / 2;
  update(node * 2, cl, mid, tl, tr, vl);
  update(node * 2 + 1, mid + 1, cr, tl, tr, vl);
  Tree[node].value = min(Tree[node * 2].value, Tree[node * 2 + 1].value);
}
pair<int, int> query(int node, int cl, int cr, int tl, int tr) {
  push(node, cl, cr);
  if (cl > tl && cr < tr) return make_pair(inf, 0);
  if (cr <= tl || cl >= tr) return Tree[node].value;
  int mid = (cl + cr) / 2;
  pair<int, int> Lf, Rf;
  Lf = query(node * 2, cl, mid, tl, tr);
  Rf = query(node * 2 + 1, mid + 1, cr, tl, tr);
  if (Lf.first != Rf.first) return min(Lf, Rf);
  if ((int)rnd() % 2 == 0)
    return Lf;
  else
    return Rf;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  build(1, 1, m);
  int L[n], R[n];
  for (int i = 0; i < n; i++) {
    cin >> L[i] >> R[i];
    if (L[i] >= 1) update(1, 1, m, 1, L[i], +1);
    if (R[i] <= m) update(1, 1, m, R[i], m, +1);
  }
  pair<int, int> cur;
  int res = 0;
  for (int i = 0; i < n; i++) {
    cur = query(1, 1, m, L[i], R[i]);
    if (cur.first >= inf) {
      res++;
    } else {
      update(1, 1, m, cur.second, cur.second, +inf + (int)1e7);
      if (L[i] >= 1) update(1, 1, m, 1, L[i], -1);
      if (R[i] <= m) update(1, 1, m, R[i], m, -1);
    }
  }
  cout << res;
  return 0;
}
