#include <bits/stdc++.h>
using namespace std;
const long long NMAX = 400000;
const long long MOD = 1000000007;
long long N, M, Ans = 0;
long long fre[2 * NMAX + 2];
vector<pair<long long, long long>> v;
multiset<long long> ST;
map<long long, vector<long long>> MP;
map<long long, vector<long long>> SCOT;
long long cid(long long nr) {
  if (nr > N) nr -= N;
  return nr;
}
int main() {
  cin >> M >> N;
  for (long long i = 1; i <= M; ++i) {
    long long x, y;
    cin >> x >> y;
    v.push_back({y, x + N});
  }
  for (long long i = 0; i < (long long)v.size(); ++i) {
    MP[v[i].first].push_back(v[i].second + 1);
    SCOT[v[i].second + 1].push_back(v[i].second + 1);
  }
  for (long long i = 1; i <= 2 * N; ++i) {
    auto sc = SCOT[i];
    for (auto x : sc) {
      ST.erase(x);
    }
    auto vv = MP[i];
    for (auto x : vv) {
      ST.insert(x);
    }
    if (!fre[cid(i)]) {
      while (!ST.empty() && ((*(ST.begin())) < i)) {
        ST.erase(ST.begin());
      }
      if (ST.empty()) continue;
      ++Ans;
      ST.erase(ST.begin());
      fre[cid(i)] = 1;
    }
  }
  cout << M - Ans << '\n';
  return 0;
}
