#include <bits/stdc++.h>
using namespace std;
struct RMQ {
  int segn2;
  pair<int, int> inf;
  vector<pair<int, int> > data;
  RMQ(int n) {
    inf = {-1000000000, 0};
    for (segn2 = 1; segn2 < n; segn2 *= 2)
      ;
    data.assign(segn2 * 2, inf);
    for (int i = 0; i < n; i++) {
      data[i + segn2 - 1] = {1000000000, i};
    }
    for (int i = segn2 - 2; i >= 0; i--) {
      data[i] = max(data[i * 2 + 1], data[i * 2 + 2]);
    }
  }
  pair<int, int> query(int a, int b, int l = 0, int r = -1, int k = 0) {
    if (r == -1) r += segn2;
    if (a <= l && r <= b) return data[k];
    if (r < a || b < l) return inf;
    return max(query(a, b, l, (l + r) / 2, k * 2 + 1),
               query(a, b, (l + r) / 2 + 1, r, k * 2 + 2));
  }
  void set(int k, int x2) {
    pair<int, int> x = {x2, k};
    k += segn2 - 1;
    data[k] = x;
    while (k > 0) {
      k = (k - 1) / 2;
      data[k] = max(data[k * 2 + 1], data[k * 2 + 2]);
    }
    return;
  }
};
int main() {
  int n, m;
  int L[100010], R[100010];
  vector<pair<int, int> > vec;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", L + i, R + i);
    vec.push_back({R[i], L[i]});
  }
  sort(vec.begin(), vec.end());
  RMQ rmq(m + 1);
  priority_queue<int> pq;
  for (int i = n - 1; i >= 0; i--) {
    int r = vec[i].first;
    int l = vec[i].second;
    if (r > m) {
      pq.push(-l);
      continue;
    }
    auto p = rmq.query(r, m);
    if (p.first == 1000000000) {
      rmq.set(p.second, l);
    } else {
      if (p.first > l) {
        rmq.set(p.second, l);
        pq.push(-p.first);
      } else {
        pq.push(-l);
      }
    }
  }
  int ans = 0;
  while (pq.size()) {
    auto p = rmq.query(1, -pq.top());
    if (p.first == 1000000000) {
      rmq.set(p.second, 1);
    } else {
      ans++;
    }
    pq.pop();
  }
  cout << ans << endl;
  return 0;
}
