#include <bits/stdc++.h>
using namespace std;
int gi() {
  int x = 0, o = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-') ch = getchar();
  if (ch == '-') o = -1, ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * o;
}
int n, m;
set<int> s;
pair<int, int> a[200010];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) s.insert(i);
  int ans = 0;
  for (int i = 1; i <= n; i++) a[i].first = gi(), a[i].second = gi();
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    int l = a[i].first, r = a[i].second;
    auto it = s.lower_bound(r);
    if (it != s.end())
      s.erase(it);
    else if (!s.empty() && *s.begin() <= l)
      s.erase(s.begin());
    else
      ++ans;
  }
  cout << ans;
  return 0;
}
