#include <bits/stdc++.h>
using namespace std;
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(long long &x, long long y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(long long &x, long long y) { return (y > x) ? x = y, 1 : 0; }
const int N = 10000;
const int inf = (int)1e9 + 1;
const long long big = (long long)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;
int cnt_v = 1;
long long tree[N * 4], add[N * 4];
void build(int n, int *val) {
  cnt_v = 1;
  while (cnt_v < n) cnt_v <<= 1;
  fill(tree, tree + cnt_v * 2 - 1, 0);
  fill(add, add + cnt_v * 2 - 1, 0);
  for (int i = 0; i < n; i++) {
    tree[cnt_v - 1 + i] = val[i];
    if (i > 0) {
      tree[cnt_v - 1 + i] += tree[cnt_v - 1 + i - 1];
    }
  }
  for (int i = cnt_v - 2; i > -1; i--) {
    tree[i] = max(tree[i * 2 + 1], tree[i * 2 + 2]);
  }
}
void push(int x) {
  tree[(x << 1) + 1] += add[x];
  add[(x << 1) + 1] += add[x];
  tree[(x << 1) + 2] += add[x];
  add[(x << 1) + 2] += add[x];
  add[x] = 0;
}
void upd(int x, int lx, int rx, int l, int r, long long v) {
  if (lx >= r || l >= rx)
    return;
  else if (lx >= l && rx <= r) {
    tree[x] += v;
    add[x] += v;
  } else {
    push(x);
    upd((x << 1) + 1, lx, (lx + rx) >> 1, l, r, v);
    upd((x << 1) + 2, (lx + rx) >> 1, rx, l, r, v);
    tree[x] = max(tree[(x << 1) + 1], tree[(x << 1) + 2]);
  }
}
long long get(int x, int lx, int rx, int l, int r) {
  if (lx >= r || l >= rx)
    return -big;
  else if (lx >= l && rx <= r)
    return tree[x];
  else {
    push(x);
    return max(get(x * 2 + 1, lx, (lx + rx) / 2, l, r),
               get(x * 2 + 2, (lx + rx) / 2, rx, l, r));
  }
}
int val[N];
vector<pair<int, int> > e1[N + 1];
vector<pair<int, int> > e2[N + 1];
int main() {
  int T;
  T = 1;
  while (T--) {
    int n, m;
    scanf("%d %d", &m, &n);
    for (int i = 0; i < n; i++) {
      val[i] = 1;
    }
    for (int i = 0; i < n; i++) {
      e1[i].clear();
      e2[i].clear();
    }
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      y = n - y + 1;
      if (x + y >= n) {
        continue;
      }
      y = n - y - 1;
      e1[x].push_back({x, y});
      e2[y + 1].push_back({x, y});
    }
    build(n, val);
    long long ans = m;
    for (int i = 0; i < n; i++) {
      for (auto &it : e1[i]) {
        int x = it.first, y = it.second;
        upd(0, 0, cnt_v, x, y + 1, 1);
      }
      for (auto &it : e2[i]) {
        int x = it.first, y = it.second;
        upd(0, 0, cnt_v, x, y + 1, -1);
      }
      setmax(ans, tree[0]);
      upd(0, 0, cnt_v, i, n, -val[i]);
    }
    long long sum = 0;
    for (int i = 0; i < n; i++) {
      sum += val[i];
    }
    sum = min(0LL, sum - ans);
    cout << m - (m + sum) << "\n";
  }
  return 0;
}
