#include <bits/stdc++.h>
using namespace std;
namespace SGT {
pair<int, int> minn[800000];
pair<int, int> query(int l, int r, int o, int lx, int rx) {
  if (l >= lx && r <= rx)
    return minn[o];
  else {
    int m = ((l + r) >> 1);
    if (m >= rx) return query(l, m, o * 2, lx, rx);
    if (m < lx) return query(m + 1, r, o * 2 + 1, lx, rx);
    return min(query(l, m, o * 2, lx, rx), query(m + 1, r, o * 2 + 1, lx, rx));
  }
}
void update(int l, int r, int o, int p, pair<int, int> q) {
  if (l == r)
    minn[o] = q;
  else {
    int m = ((l + r) >> 1);
    if (m >= p)
      update(l, m, o * 2, p, q);
    else
      update(m + 1, r, o * 2 + 1, p, q);
    minn[o] = min(minn[o * 2], minn[o * 2 + 1]);
  }
}
}  // namespace SGT
pair<int, int> q[200005];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    q[i] = pair<int, int>(x, y);
  }
  sort(q + 1, q + n + 1);
  int lx = 0, rx = m + 1, ans = 0;
  for (int i = 1; i <= n; i++) {
    if (lx == rx - 1) break;
    if (q[i].first > lx) {
      lx++;
      ans++;
      SGT::update(1, m, 1, lx, pair<int, int>(q[i].second, lx));
    } else if (q[i].second < rx) {
      rx--;
      ans++;
      SGT::update(1, m, 1, rx, pair<int, int>(q[i].second, rx));
    } else {
      pair<int, int> t(0x3f3f3f3f, 0x3f3f3f3f);
      if (q[i].first) t = min(t, SGT::query(1, m, 1, 1, q[i].first));
      if (q[i].second <= m) t = min(t, SGT::query(1, m, 1, q[i].second, m));
      if (t.first < rx) {
        rx--;
        ans++;
        SGT::update(1, m, 1, rx, pair<int, int>(t.first, rx));
        SGT::update(1, m, 1, t.second, pair<int, int>(q[i].second, t.second));
      }
    }
  }
  printf("%d\n", n - ans);
  return 0;
}
