#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 2;
int n, m, x[N], y[N], l[N], r[N];
vector<int> g[N];
bool vaz[N];
bool dfs(int nod) {
  if (vaz[nod]) return 0;
  vaz[nod] = 1;
  for (auto i : g[nod]) {
    if (!l[i] || dfs(l[i])) {
      l[i] = nod;
      r[nod] = i;
      return 1;
    }
  }
  return 0;
}
int match() {
  int ans = 0;
  for (bool ok = 1; ok;) {
    ok = 0;
    memset(vaz, 0, sizeof vaz);
    for (int i = 1; i <= n; ++i)
      if (!r[i]) ok |= dfs(i);
  }
  for (int i = 1; i <= n; ++i)
    if (r[i]) ++ans;
  return ans;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> x[i] >> y[i];
    for (int j = 1; j <= x[i]; ++j) {
      g[i].push_back(j + n);
    }
    for (int j = y[i]; j <= m && j - i <= 80; ++j) g[i].push_back(j + n);
    for (int j = x[i]; j >= 1 && x[i] - j <= 80; --j) g[i].push_back(j + n);
    for (int j = m; j >= y[i] && m - j <= 80; --j) g[i].push_back(j + n);
  }
  cout << n - match();
}
