#include <bits/stdc++.h>
using namespace std;
void fastIO() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
template <typename T, typename U>
inline void mnze(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
inline void mxze(T &x, U y) {
  if (x < y) x = y;
}
void _scan(int &x) { scanf("%d", &x); }
void _scan(long long &x) { scanf("%lld", &x); }
void _scan(double &x) { scanf("%lf", &x); }
void _scan(char &x) { scanf(" %c", &x); }
void _scan(char *x) { scanf("%s", x); }
void scan() {}
template <typename T, typename... U>
void scan(T &head, U &...tail) {
  _scan(head);
  scan(tail...);
}
template <typename T>
void _dbg(const char *sdbg, T h) {
  cerr << sdbg << "=" << h << "\n";
}
template <typename T, typename... U>
void _dbg(const char *sdbg, T h, U... t) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << "=" << h << ",";
  _dbg(sdbg + 1, t...);
}
struct seg {
  int L, R;
};
const int MAXN = 2e5 + 5;
int n, m;
seg s[MAXN];
vector<int> Rs[MAXN];
pair<int, int> solve(int p) {
  priority_queue<int> pq;
  for (int i = p + 1; i < (int)m + 1; i++)
    for (auto r : Rs[i]) pq.push(r);
  int lr = 0, rr = 0;
  for (int i = p; i > (int)0; i--) {
    for (auto r : Rs[i]) pq.push(r);
    if (pq.empty()) continue;
    int r = pq.top();
    pq.pop();
    lr++;
  }
  for (auto r : Rs[0]) pq.push(r);
  for (int i = m; i > (int)p; i--) {
    while (!pq.empty() && pq.top() > i) pq.pop();
    if (pq.empty()) continue;
    int r = pq.top();
    pq.pop();
    rr++;
  }
  return {lr, rr};
}
int main() {
  scan(n, m);
  for (int i = 0; i < (int)n; i++) scan(s[i].L, s[i].R);
  for (int i = 0; i < (int)n; i++) Rs[s[i].L].push_back(s[i].R);
  int lo = 0, hi = m;
  while (lo < hi) {
    int mi = (lo + hi + 1) >> 1;
    (lo, mi, hi);
    pair<int, int> ret = solve(mi);
    if (ret.first + ret.second == n)
      lo = hi = mi;
    else {
      if (ret.first == mi)
        lo = mi;
      else
        hi = mi - 1;
    }
  }
  pair<int, int> ret = solve(lo);
  int ans = ret.first + ret.second;
  for (int p = 0; p < (int)m; p++) mxze(ans, solve(p).first + solve(p).second);
  for (int p = 0; p < (int)m; p++) (p, solve(p).first, solve(p).second);
  printf("%d\n", n - ans);
}
