#include <bits/stdc++.h>
using namespace std;
vector<int> query[200005];
int n, m;
bool check(int X) {
  priority_queue<int, vector<int>, greater<int> > que;
  set<int> zan;
  set<int>::iterator it;
  for (int i = 1; i <= m; i++) zan.insert(i);
  int cnt = X;
  for (int i = 0; i <= m; i++) {
    if (zan.count(i)) {
      cnt++;
      zan.erase(i);
    }
    for (int j = 0; j < query[i].size(); j++) {
      int to = query[i][j];
      if (cnt > 0) {
        cnt--;
        que.push(to);
      } else {
        que.push(to);
        int tp = que.top();
        que.pop();
        it = zan.lower_bound(tp);
        if (it == zan.end()) return false;
        zan.erase(it);
      }
    }
  }
  return true;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    query[l].push_back(r);
  }
  int low = -1, up = n;
  while (up - low > 1) {
    int d = (up + low) / 2;
    if (check(d))
      up = d;
    else
      low = d;
  }
  printf("%d\n", up);
  return 0;
}
