#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int maxn = 2e5 + 5;
int n, m;
pair<int, int> a[maxn];
vector<pair<int, int> > vec;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (0); i < (n); ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    --l;
    --r;
    a[i] = make_pair(l, r);
  }
  sort(a, a + n);
  priority_queue<pair<int, int> > q;
  for (int i = (0); i < (n); ++i) {
    q.push(make_pair(a[i].second, i));
    while (q.size() > a[i].first) {
      pair<int, int> j = q.top();
      vec.push_back(j);
      q.pop();
    }
  }
  sort(vec.begin(), vec.end());
  int cnt = 0;
  for (int i = vec.size() - 1; i >= 0; --i) {
    if (cnt >= m - vec[i].first + 1) continue;
    ++cnt;
  }
  printf("%d\n", vec.size() - cnt);
  return 0;
}
