#include <bits/stdc++.h>
template <class T>
inline void read(T& x) {
  x = 0;
  bool f = 0;
  char c = getchar();
  for (; c < '0' || c > '9'; c = getchar()) f = (c == '-');
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  x = f ? -x : x;
}
const int MAXN(200010);
int n, m, Ans, l, r;
struct Data {
  int x, num;
} L[MAXN], R[MAXN];
bool cmp1(Data A, Data B) { return A.x < B.x; }
bool cmp2(Data A, Data B) { return A.x > B.x; }
bool ok[MAXN], bf[MAXN];
int main() {
  read(n);
  read(m);
  for (int i = 1; i <= n; i++) {
    read(l), read(r);
    L[i].x = l;
    L[i].num = i;
    R[i].x = r;
    R[i].num = i;
  }
  std::sort(L + 1, L + 1 + n, cmp1);
  std::sort(R + 1, R + 1 + n, cmp2);
  for (int i = 1, j = 1, li = 1, ri = m;;) {
    if (bf[li] || bf[ri]) break;
    while ((ok[L[i].num] || L[i].x < li) && i <= n) i++;
    while ((ok[R[j].num] || R[j].x > ri) && j <= n) j++;
    if ((L[i].x - li + 1 < ri - R[j].x + 1 && i <= n) || j > n)
      bf[li++] = 1, ok[L[i++].num] = 1;
    else if (i <= n)
      bf[ri--] = 1, ok[R[j++].num] = 1;
  }
  for (int i = 1; i <= n; i++)
    if (!ok[i]) Ans++;
  printf("%d\n", Ans);
  return 0;
}
