#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int n, m;
const int MAXN = 1 << 18;
int tree[MAXN * 8], val[MAXN * 8];
void increase(int a) {
  a += MAXN - 1;
  tree[a] += 1;
  val[a] = tree[a] - (a - MAXN + 1);
  a >>= 1;
  while (a) {
    tree[a] = tree[a << 1] + tree[(a << 1) + 1];
    val[a] = max(val[a << 1], val[(a << 1) + 1] + tree[a << 1]);
    a >>= 1;
  }
}
int query(int a, int b, int now = 1, int l = 1, int r = MAXN + 1) {
  if (r <= a || l >= b) {
    return -INF;
  }
  if (r <= b && l >= a) {
    return val[now];
  }
  int mid = (l + r) >> 1;
  return max(query(a, b, now << 1, l, mid),
             query(a, b, (now << 1) + 1, mid, r));
}
set<pair<int, int> > s;
pair<int, int> sq[200000 + 2];
bool cmp(pair<int, int> A, pair<int, int> B) { return A.second < B.second; }
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  memset(val, -63, sizeof(val));
  for (int i = 1; i <= n; ++i)
    cin >> sq[i].first >> sq[i].second, sq[i].first++;
  sort(sq + 1, sq + 1 + n, cmp);
  int it = n;
  int res = n;
  for (int i = m; i >= 1; --i) {
    while (it && sq[it].second >= i) {
      pair<int, int> now = sq[it--];
      increase(now.first);
    }
    res = max(res, query(1, m + 1) + i);
  }
  res = n + m - res;
  res = min(res, n);
  cout << n - res << endl;
  return 0;
}
