#include <bits/stdc++.h>
using namespace std;
template <class S, class T>
pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {
  return pair<S, T>(s.first + t.first, s.second + t.second);
}
template <class S, class T>
pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) {
  return pair<S, T>(s.first - t.first, s.second - t.second);
}
template <class S, class T>
ostream &operator<<(ostream &os, pair<S, T> p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long inf = 1000000001;
const long long INF = (long long)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
long long dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
long long dx2[8] = {1, 1, 0, -1, -1, -1, 0, 1},
          dy2[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long MOD = 1000000007;
long long n, m;
vector<long long> memo;
long long f(long long mid, vector<pair<long long, long long> > &lr) {
  if (memo[mid] != -1) return memo[mid];
  long long idx = 0;
  priority_queue<long long> pq;
  long long res = 0;
  while (idx < n and lr[idx].first >= mid) {
    pq.push(lr[idx].second);
    idx++;
  }
  for (long long i = mid - 1; i >= 0; i--) {
    while (idx < n and lr[idx].first >= i) {
      pq.push(lr[idx].second);
      idx++;
    }
    if (pq.size() > 0) {
      pq.pop();
      res++;
    }
  }
  while (idx < n) {
    pq.push(lr[idx].second);
    idx++;
  }
  for (long long i = m - 1; i >= mid; i--) {
    while (pq.size() > 0) {
      long long to = pq.top();
      pq.pop();
      if (to <= i) {
        res++;
        break;
      }
    }
    if (pq.size() == 0) break;
  }
  memo[mid] = res;
  return res;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ;
  cin >> n >> m;
  memo.resize(m + 2);
  fill(memo.begin(), memo.end(), -1);
  vector<pair<long long, long long> > lr(n);
  for (long long i = 0; i < (n); i++) {
    cin >> lr[i].first >> lr[i].second;
    lr[i].first--;
    lr[i].second--;
  }
  auto cmp = [](pair<long long, long long> a, pair<long long, long long> b) {
    if (a.first != b.first)
      return a.first > b.first;
    else
      return a < b;
  };
  sort(lr.begin(), lr.end(), cmp);
  long long l = 0, r = m;
  while (l + 2 < r) {
    long long x1 = (2 * l + r) / 3, x2 = (l + 2 * r) / 3;
    long long y1 = f(x1, lr), y2 = f(x2, lr);
    if (y1 == y2) {
      l = x1;
      r = x1;
      break;
    }
    if (y1 > y2) {
      r = x2;
    } else {
      l = x1;
    }
  }
  long long ma = 0;
  for (long long i = l; i <= r; i++) {
    chmax(ma, f(i, lr));
  }
  cout << n - ma << endl;
}
