#include <bits/stdc++.h>
using namespace std;
template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()) {
  v.assign(a, vector<T>(b, t));
}
template <class F, class T>
void convert(const F &f, T &t) {
  stringstream ss;
  ss << f;
  ss >> t;
}
void mainmain() {
  int n, m;
  cin >> n >> m;
  vector<vector<int> > vv(3 * m);
  vector<int> dp(3 * m);
  multiset<int> second;
  for (int(i) = (0); (i) < ((n)); ++(i)) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    vv[b].push_back(a + m);
  }
  for (int(i) = (0); (i) < ((3 * m)); ++(i)) {
    if (i) dp[i] = dp[i - 1];
    for (cauto x : vv[i]) {
      second.insert(x);
    }
    while (second.size() && *second.begin() < i) second.erase(second.begin());
    if (second.size()) {
      dp[i]++;
      second.erase(second.begin());
    }
  }
  int ans = 0;
  for (int(i) = (0); (i) < ((2 * m)); ++(i)) {
    ans = max(ans, dp[i + m] - dp[i]);
  }
  cout << n - ans << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);
  mainmain();
}
