#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int d[N];
vector<int> rec;
int main() {
  int n, m, l, r;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &l, &r);
    d[0]++, d[l + 1]--;
    d[r]++, d[m + 1]--;
  }
  for (int i = 1; i <= m; i++) {
    d[i] += d[i - 1];
    if (d[i]) rec.push_back(-d[i]);
  }
  int ans = 0, ind = 0;
  if (n > m) {
    ans = n - m;
    for (int i = 0; i < ans; i++) rec.push_back(-n);
  }
  sort(rec.begin(), rec.end());
  for (int i = 0; i < n; i++) {
    if (ind >= rec.size()) {
      ans++;
      continue;
    }
    if (ind < rec.size() && -rec[ind] >= n - i)
      ind++;
    else
      ans++;
  }
  printf("%d\n", ans);
  return 0;
}
