#include <bits/stdc++.h>
using namespace std;
template <typename F, typename S>
static istream& operator>>(istream& stream, pair<F, S>& t) {
  return stream >> t.first >> t.second;
}
template <typename T>
static ostream& operator<<(ostream& stream, const vector<T>& t);
template <typename T>
static istream& read(T, T, istream& = cin);
template <typename T>
static istream& operator>>(istream& stream, vector<T>& t) {
  return read((t).begin(), (t).end(), stream);
}
template <typename T>
static istream& read(T b, T e, istream& stream) {
  for (T it = b; it != e; ++it) stream >> *it;
  return stream;
}
template <typename T>
static void print(T x, string end = "\n") {
  cout << x << end;
}
bool comp(const pair<int, int>& a, const pair<int, int>& b) {
  if (a.first != b.first) return a.first < b.first;
  return a.second > b.second;
}
void _() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> arr(n);
  cin >> arr;
  sort((arr).begin(), (arr).end(), comp);
  vector<int> other;
  int l = 0;
  while (l < n && arr[l].first == 0) {
    other.push_back(arr[l].second);
    ++l;
  }
  priority_queue<int, vector<int>, greater<int>> pq;
  for (int coord = 1; coord <= m; ++coord) {
    while (l < n && arr[l].first <= coord) {
      pq.push(arr[l].second);
      ++l;
    }
    while (long long(pq.size()) > coord) {
      other.push_back(pq.top());
      pq.pop();
    }
  }
  int ans = n - long long(pq.size());
  int r = 0;
  sort((other).rbegin(), (other).rend());
  for (int i = m; i >= 1; --i) {
    while (r < long long(other.size()) && other[r] > i) {
      ++r;
    }
    if (r < long long(other.size())) {
      --ans;
      ++r;
    }
  }
  print(ans);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);
  _();
}
