#include <bits/stdc++.h>
using namespace std;
struct Section {
  int l, r;
  bool operator<(const Section& rhs) const {
    return r != rhs.r ? r > rhs.r : l < rhs.l;
  }
} sec[200010];
int seg[800040];
void modify(int l, int r, int pos, int idx) {
  if (l == r) {
    seg[idx] = 1;
  } else {
    int mid = (l + r) >> 1;
    if (pos <= mid)
      modify(l, mid, pos, idx << 1);
    else
      modify(mid + 1, r, pos, idx << 1 | 1);
    seg[idx] = seg[idx << 1] + seg[idx << 1 | 1];
  }
}
int query_left(int l, int r, int ql, int qr, int idx) {
  if (l == ql && r == qr) {
    if (seg[idx] == r - l + 1) return -1;
    while (l != r) {
      int mid = (l + r) >> 1;
      if (seg[idx << 1] == mid + 1 - l)
        l = mid + 1;
      else
        r = mid;
    }
    return l;
  } else {
    int mid = (l + r) >> 1;
    if (qr <= mid)
      return query_left(l, mid, ql, qr, idx << 1);
    else if (ql > mid)
      return query_left(mid + 1, r, ql, qr, idx << 1 | 1);
    else {
      int tmp = query_left(l, mid, ql, mid, idx << 1);
      if (tmp != -1) return tmp;
      return query_left(mid + 1, r, mid + 1, qr, idx << 1 | 1);
    }
  }
}
int query_right(int l, int r, int ql, int qr, int idx) {
  if (l == ql && r == qr) {
    if (seg[idx] == r - l + 1) return -1;
    while (l != r) {
      int mid = (l + r) >> 1;
      if (seg[idx << 1 | 1] == r - mid)
        r = mid;
      else
        l = mid + 1;
    }
    return l;
  } else {
    int mid = (l + r) >> 1;
    if (qr <= mid)
      return query_right(l, mid, ql, qr, idx << 1);
    else if (ql > mid)
      return query_right(mid + 1, r, ql, qr, idx << 1 | 1);
    else {
      int tmp = query_right(mid + 1, r, mid + 1, qr, idx << 1 | 1);
      if (tmp != -1) return tmp;
      return query_right(l, mid, ql, mid, idx << 1);
    }
  }
}
vector<int> ls;
int main() {
  int N, M, l, r;
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; i++) {
    scanf("%d%d", &l, &r);
    sec[i] = (Section){l, r};
  }
  sort(sec, sec + N);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    l = sec[i].l, r = sec[i].r;
    bool ok = false;
    if (r <= M) {
      int pos = query_right(1, M, r, M, 1);
      if (pos != -1) {
        modify(1, M, pos, 1);
        ok = true;
      }
    }
    if (!ok) {
      if (l >= 1)
        ls.push_back(l);
      else
        ans++;
    }
  }
  sort(ls.begin(), ls.end());
  for (size_t i = 0; i < ls.size(); i++) {
    l = ls[i];
    bool ok = false;
    int pos = query_left(1, M, 1, l, 1);
    if (pos != -1) {
      modify(1, M, pos, 1);
      ok = true;
    }
    if (!ok) ans++;
  }
  printf("%d\n", ans);
  return 0;
}
