#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = (long long)1000000007 * 1000000007;
const long double eps = 1e-11;
const long double pi = acos(-1.0);
vector<pair<int, int>> v[600000];
int hum[200000];
int seat[200000];
int main() {
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      q;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    v[r].push_back({m + l, i});
    v[r + m].push_back({2 * m + l, i});
  }
  fill(hum, hum + n, -1);
  for (int i = 0; i < 3 * m; i++) {
    int len = v[i].size();
    for (int j = 0; j < len; j++) {
      q.push(v[i][j]);
    }
    if (seat[i % m]) continue;
    while (!q.empty()) {
      pair<int, int> x = q.top();
      q.pop();
      int y = x.second;
      if (i > x.first) continue;
      int z = x.first % m;
      if (hum[y] >= 0) {
        if ((i % m > z && i % m <= hum[y] && hum[y] <= z + m) ||
            (i % m <= z && i % m <= hum[y] && hum[y] <= z)) {
          seat[hum[y]] = 0;
          hum[y] = i % m;
          seat[hum[y]] = 1;
        }
      } else {
        hum[y] = i % m;
        seat[i % m] = 1;
      }
      break;
    }
  }
  int out = 0;
  for (int i = 0; i < m; i++) {
    if (seat[i]) out++;
  }
  cout << n - out << endl;
  return 0;
}
