#include <bits/stdc++.h>
using namespace std;
struct Range {
  int x, y, id;
  bool operator<(const Range &that) const {
    if (x == that.x) {
      return y < that.y;
    }
    return x > that.x;
  }
};
int main() {
  freopen("atc.in", "r", stdin);
  int n, m;
  cin >> n >> m;
  vector<Range> intervs;
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    intervs.push_back(Range{1, x, i});
    if (y != m + 1) intervs.push_back(Range{y, m, i});
  }
  sort(intervs.begin(), intervs.end());
  int matt = n;
  vector<int> cup(n);
  set<int> points;
  for (int i = 1; i <= m; ++i) points.insert(i);
  for (int i = 0; i < intervs.size(); ++i) {
    if (cup[intervs[i].id]) continue;
    auto it = points.lower_bound(intervs[i].x);
    if (it != end(points) && *it <= intervs[i].y) {
      points.erase(it);
      matt--;
      cup[intervs[i].id] = 1;
    }
  }
  cout << matt;
}
