#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, m, done[N];
int L[N], R[N];
vector<int> lf[N], rf[N];
bool ok(int st) {
  int cnt = 0;
  for (int i = st; i >= 1; --i) {
    cnt += (int)(lf[i].size());
    if (!cnt) return false;
    cnt -= 1;
  }
  return true;
}
int get(int st) {
  int ret = 0;
  int have = 0;
  priority_queue<pair<int, int> > q;
  for (int i = st; i >= 1; --i) {
    for (auto u : lf[i]) {
      q.push({R[u], u});
    }
    done[q.top().second] = 1;
    q.pop();
    ++ret;
  }
  for (int i = 1; i <= st; ++i) {
    for (auto u : rf[i])
      if (!done[u]) ++have;
  }
  for (int i = st + 1; i <= m; ++i) {
    for (auto u : rf[i])
      if (!done[u]) ++have;
    if (have) {
      ++ret;
      --have;
    }
  }
  return n - ret;
}
void solve() {
  int lo = 0, hi = m, ret = -1;
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    if (ok(mid))
      ret = mid, lo = mid + 1;
    else
      hi = mid - 1;
  }
  printf("%d\n", get(ret));
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d", &L[i], &R[i]);
    lf[L[i]].push_back(i);
    rf[R[i]].push_back(i);
  }
  solve();
  return 0;
}
