#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const long long int MAX = 1e9 + 7;
void array_show(int *array, int array_n, char middle = ' ') {
  for (int i = 0; i < array_n; i++)
    printf("%d%c", array[i], (i != array_n - 1 ? middle : '\n'));
}
void array_show(long long int *array, int array_n, char middle = ' ') {
  for (int i = 0; i < array_n; i++)
    printf("%lld%c", array[i], (i != array_n - 1 ? middle : '\n'));
}
void array_show(vector<int> &vec_s, int vec_n = -1, char middle = ' ') {
  if (vec_n == -1) vec_n = vec_s.size();
  for (int i = 0; i < vec_n; i++)
    printf("%d%c", vec_s[i], (i != vec_n - 1 ? middle : '\n'));
}
void array_show(vector<long long int> &vec_s, int vec_n = -1,
                char middle = ' ') {
  if (vec_n == -1) vec_n = vec_s.size();
  for (int i = 0; i < vec_n; i++)
    printf("%lld%c", vec_s[i], (i != vec_n - 1 ? middle : '\n'));
}
vector<pair<int, int> > v1;
vector<int> v2;
priority_queue<int, vector<int>, greater<int> > q1;
int main() {
  int n, m;
  int i, j, k;
  int a, b, c;
  int p, q;
  int s = 0;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> a >> b;
    v1.push_back(make_pair(a, b));
  }
  sort(v1.begin(), v1.end());
  p = 0;
  for (auto node : v1) {
    a = node.first;
    q1.push(node.second);
    if (p >= a) {
      v2.push_back(q1.top()), q1.pop();
    } else {
      p++;
    }
  }
  sort(v2.rbegin(), v2.rend());
  p = m;
  for (auto node : v2) {
    if (node > p)
      s++;
    else
      p--;
  }
  s = max(m - n, s);
  cout << s << endl;
}
