#include <bits/stdc++.h>
void read(int &x) {
  x = 0;
  int flag = 1;
  char ch = ' ';
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= flag;
}
void read(long long &x) {
  x = 0;
  int flag = 1;
  char ch = ' ';
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= flag;
}
using namespace std;
const int maxn = 200010;
int n, m, pos[maxn], remain[maxn], l[maxn];
struct Data {
  int num, l, r;
  Data() {}
  Data(int a, int b, int c) { num = a, l = b, r = c; }
  bool operator<(const Data &a) const { return r > a.r; }
} a[maxn];
bool flag[maxn];
priority_queue<Data> pq;
bool cmp(Data a, Data b) { return (a.l == b.l && a.r < b.r) || a.l < b.l; }
int main() {
  read(n), read(m);
  for (int i = 1; i <= (int)n; i++) read(a[i].l), read(a[i].r);
  sort(a + 1, a + 1 + n, cmp);
  int cur = 1, ans = 0;
  flag[m + 1] = 1;
  for (int i = 1; i <= (int)n; i++) a[i].num = i;
  for (int i = 1; i <= (int)n; i++) {
    if (cur <= a[i].l && cur <= m)
      pos[i] = cur, flag[cur++] = 1, pq.push(a[i]), ans++;
    else if (!pq.empty()) {
      Data tmp = pq.top();
      if (tmp.r < a[i].r) {
        pq.pop();
        pq.push(a[i]);
        pos[i] = pos[tmp.num];
        pos[tmp.num] = 0;
      }
    }
  }
  int cnt = 0, cnt2 = 0;
  for (int i = 1; i <= (int)m; i++)
    if (!flag[i]) remain[++cnt] = m - i + 1;
  sort(remain + 1, remain + 1 + cnt);
  for (int i = 1; i <= (int)n; i++)
    if (!pos[i]) {
      int x = n - a[i].r + 1;
      l[++cnt2] = upper_bound(remain + 1, remain + 1 + cnt, x) - remain - 1;
    }
  memset(flag, 0, sizeof(flag));
  flag[cnt + 1] = 1;
  cur = 1;
  for (int i = 1; i <= (int)cnt2; i++)
    if (cur <= l[i] && cur <= cnt) cur++, ans++;
  printf("%d\n", n - ans);
  return 0;
}
