#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5 + 6;
vector<int> v[MAX_N];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; n >= i; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    v[x].push_back(y);
  }
  for (int i = 0; m + 1 >= i; i++) {
    sort(v[i].begin(), v[i].end());
  }
  priority_queue<int, vector<int>, greater<int> > pq;
  for (int i = 0; m >= i; i++) {
    if (i == 0) {
      for (int j : v[i]) {
        pq.push(j);
      }
    } else {
      if (v[i].size() == 0) {
        if (!pq.empty() && pq.top() <= i) pq.pop();
      } else {
        for (int j = 0; v[i].size() - 1 > j; j++) {
          pq.push(v[i][j]);
        }
      }
    }
  }
  printf("%d\n", pq.size());
}
