#include <bits/stdc++.h>
using namespace std;
template <class T>
using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<pair<int, int> > lrs(n);
  for (int i = 0; (i) < int(n); ++(i)) {
    int l, r;
    scanf("%d%d", &l, &r);
    --l;
    --r;
    lrs[i] = {l, r};
  }
  sort(begin(lrs), end(lrs));
  int left = 0;
  reversed_priority_queue<int> unused_rs;
  vector<int> rs;
  for (auto lr : lrs) {
    int l, r;
    tie(l, r) = lr;
    if (l == -1 and r == m) {
    } else if (l == -1) {
      rs.push_back(r);
    } else {
      if (left <= l) {
        ++left;
        unused_rs.push(r);
      } else {
        unused_rs.push(r);
        int min_r = unused_rs.top();
        unused_rs.pop();
        rs.push_back(min_r);
      }
    }
    if (left == m) {
      break;
    }
  }
  int right = m;
  sort(begin(rs), end(rs));
  reverse(begin(rs), end(rs));
  for (int r : rs) {
    if (r == m) {
    } else {
      if (r < right) {
        --right;
      }
    }
    if (left == right) {
      break;
    }
  }
  int used = left + (m - right);
  printf("%d\n", n - used);
  return 0;
}
