#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (auto i = begin(v); i != end(v); i++)
    os << *i << (i == end(v) - 1 ? "" : " ");
  return os;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto i = begin(v); i != end(v); i++) is >> *i;
  return is;
}
vector<pair<int, int>> inp;
vector<int> all_rs;
bool check(int added, int m) {
  vector<int> all_rs;
  multiset<int> rs;
  for (auto x : inp) {
    rs.insert(x.second);
    while (((int)rs.size() - added) > x.first) {
      int vvv = *rs.begin();
      all_rs.push_back(vvv);
      rs.erase(rs.find(vvv));
    }
  }
  sort(all_rs.begin(), all_rs.end());
  int cnt = 0;
  for (int i = all_rs.size() - 1; i >= 0; i--) {
    int val = all_rs[i];
    if (val > m) return false;
    cnt++;
    if ((m - val + 1) < cnt) return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  scanf("%d %d ", &n, &m);
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d %d ", &a, &b);
    inp.push_back({a, b});
    all_rs.push_back(b);
  }
  sort(inp.begin(), inp.end());
  sort(all_rs.begin(), all_rs.end(), std::greater<int>());
  int left = 0, right = (n + 1);
  while (left < right) {
    int mm = (left + right) / 2;
    if (check(mm, m)) {
      right = mm;
    } else {
      left = mm + 1;
    }
  }
  printf("%d", left);
  return 0;
}
