#include <bits/stdc++.h>
using namespace std;
int get() {
  char ch;
  while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')
    ;
  if (ch == '-') {
    int s = 0;
    while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - '0';
    return -s;
  }
  int s = ch - '0';
  while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - '0';
  return s;
}
const int N = 2e+5 + 5;
int n, m;
int pre[N], suf[N];
int pv[N];
int main() {
  n = get();
  m = get();
  for (int i = 1; i <= n; i++) {
    int l = get(), r = get();
    pre[l]++, pre[r]++;
    suf[l]++, suf[r]++;
  }
  pv[0] = pre[0];
  for (int i = 1; i <= m; i++) {
    pre[i] += pre[i - 1];
    pv[i] = max(pv[i - 1], pre[i] - i);
  }
  int ans = suf[m + 1];
  for (int i = m; i >= 1; i--) {
    suf[i] += suf[i + 1];
    ans = max(ans, pv[i - 1] + suf[i] - (m - i + 1));
  }
  ans -= n;
  ans = max(ans, 0);
  printf("%d\n", ans);
  return 0;
}
