#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
struct node {
  int l, r, v;
  int mid() { return (r + l) / 2; }
};
struct seg_tree {
  node tree[MAXN << 2];
  void build(int l, int r, int x) {
    tree[x].l = l, tree[x].r = r;
    if (l == r) return;
    int mid = tree[x].mid();
    build(l, mid, x << 1);
    build(mid + 1, r, x << 1 | 1);
  }
  void insert(int st, int ed, int x) {
    if (tree[x].l >= st && tree[x].r <= ed) {
      tree[x].v = tree[x].r - tree[x].l + 1;
      return;
    }
    int mid = tree[x].mid();
    if (mid >= st) insert(st, ed, x << 1);
    if (mid < ed) insert(st, ed, x << 1 | 1);
    tree[x].v = tree[x << 1].v + tree[x << 1 | 1].v;
  }
} seg;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  seg.build(1, m, 1);
  int cnt = 0;
  for (int i = 1, l, r; i <= n; i++) {
    scanf("%d%d", &l, &r);
    if (l >= 1) seg.insert(1, l, 1);
    if (r <= m) seg.insert(r, m, 1);
    if (seg.tree[1].v >= cnt + 1) cnt++;
  }
  cout << n - cnt;
  return 0;
}
