#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1 << 18;
int n;
pair<long long, long long> dat[2 * MAX_N - 1];
void init(int n_) {
  n = 1;
  while (n < n_) n *= 2;
  for (int i = 0; i < 2 * n - 1; i++) dat[i] = pair<long long, long long>(0, 0);
}
void update(int k, pair<long long, long long> p) {
  k += n - 1;
  dat[k] = p;
  while (k > 0) {
    k = (k - 1) / 2;
    dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
  }
}
pair<long long, long long> query(int a, int b, int k = 0, int l = 0,
                                 int r = n) {
  if (r <= a || b <= l) return pair<long long, long long>(1e6, 0);
  if (a <= l && r <= b)
    return dat[k];
  else {
    pair<long long, long long> vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    pair<long long, long long> vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
}
int N, M;
int L[300001];
int R[300001];
bool used[300001];
vector<pair<long long, long long> > v;
vector<int> que;
int main() {
  cin >> N >> M;
  for (int i = 0; i < (N); i++) {
    cin >> L[i] >> R[i];
    v.push_back(pair<long long, long long>(R[i], -L[i]));
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  init(M + 10);
  for (int i = 0; i < (M + 10); i++) {
    update(i, pair<long long, long long>(-i, i));
    used[i] = false;
  }
  update(0, pair<long long, long long>(1e6, 0));
  used[0] = true;
  for (int i = 0; i < (N); i++) {
    pair<long long, long long> q = query(0, -v[i].second + 1);
    if (q.first == 1e6) {
      que.push_back(v[i].first);
    } else {
      used[q.second] = true;
      update(q.second, pair<long long, long long>(1e6, 0));
    }
  }
  sort(que.begin(), que.end());
  int count = 0;
  for (int i = 0; i < (M + 1); i++) {
    if (que.size() == count) break;
    if (used[i] == false) {
      if (que[count] <= i) {
        count++;
      }
    }
  }
  cout << que.size() - count << endl;
  return (0);
}
