#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > vec;
const int N = 1 << 18;
bool flag[200001];
int main(void) {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    pair<int, int> p;
    scanf("%d%d", &p.first, &p.second);
    vec.push_back(p);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  priority_queue<pair<int, int> > que;
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      que2;
  int l = 0;
  memset(flag, false, sizeof(flag));
  for (int i = m; i >= 1; i--) {
    while (l < n && vec[l].first >= i) {
      que.push(pair<int, int>(vec[l].second, l));
      l++;
    }
    if (que.size()) {
      pair<int, int> p = que.top();
      que.pop();
      flag[i] = true;
    }
  }
  for (; l < n; l++) {
    que.push(pair<int, int>(vec[l].second, l));
  }
  while (que.size()) {
    pair<int, int> p = que.top();
    que.pop();
    que2.push(p);
  }
  for (int i = 1; i <= m; i++) {
    if (!flag[i]) {
      if (que2.size()) {
        pair<int, int> p = que2.top();
        if (i >= p.first) {
          que2.pop();
        }
      }
    }
  }
  int res = (int)que2.size();
  printf("%d\n", res);
  return 0;
}
