#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
set<pair<int, int> > q;
vector<int> v[200000 + 5], V[200000 + 5];
int n, m, l[200000 + 5], r[200000 + 5], ans = 0, b[200000 + 5];
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; ++i) {
    l[i] = read();
    r[i] = read();
    if (l[i]) q.insert(make_pair(r[i], i)), v[l[i]].push_back(i);
    V[r[i]].push_back(i);
  }
  for (int i = 1; i <= m; ++i) {
    for (int j = 0; j < V[i].size(); ++j) q.insert(make_pair(0, V[i][j]));
    if (q.size()) {
      int x = q.begin()->second;
      q.erase(q.begin());
      b[x] = 1;
      ++ans;
    }
    for (int j = 0; j < v[i].size(); ++j)
      if (!b[v[i][j]]) q.erase(q.find(make_pair(r[v[i][j]], v[i][j])));
  }
  cout << n - ans;
  return 0;
}
