#include <bits/stdc++.h>
const int N = 200000 + 10;
int n, m;
std::vector<int> pool[N];
int tag[2 * N], max[2 * N];
inline int pos(int l, int r) { return (l + r) | (l != r); }
void apply(int l, int r, int v) {
  int id = pos(l, r);
  max[id] += v;
  tag[id] += v;
}
void release(int l, int r) {
  int id = pos(l, r), mid = (l + r) >> 1;
  if (tag[id]) {
    apply(l, mid, tag[id]);
    apply(mid + 1, r, tag[id]);
    tag[id] = 0;
  }
}
void update(int l, int r) {
  int id = pos(l, r), mid = (l + r) >> 1;
  int lch = pos(l, mid), rch = pos(mid + 1, r);
  max[id] = std::max(max[lch], max[rch]);
}
void build(int l, int r) {
  int id = pos(l, r);
  max[id] = r;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(l, mid);
  build(mid + 1, r);
}
void add(int l, int r, int p, int q, int v) {
  if (p <= l && r <= q) {
    apply(l, r, v);
    return;
  }
  release(l, r);
  int mid = (l + r) >> 1;
  if (p <= mid) add(l, mid, p, q, v);
  if (q > mid) add(mid + 1, r, p, q, v);
  update(l, r);
}
int query(int l, int r, int p, int q) {
  if (p <= l && r <= q) return max[pos(l, r)];
  release(l, r);
  int mid = (l + r) >> 1, res = 0;
  if (p <= mid) res = query(l, mid, p, q);
  if (q > mid) res = std::max(res, query(mid + 1, r, p, q));
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    pool[l].push_back(r);
  }
  build(1, m);
  int ans = std::max(n, m);
  for (int i = 0; i < m; ++i) {
    for (auto j : pool[i]) add(1, m, 1, j - 1, 1);
    ans = std::max(ans, query(1, m, i + 1, m) - i);
  }
  printf("%d\n", n - (n + m - ans));
  return 0;
}
