#include <bits/stdc++.h>
long long mpow(long long a, long long n, long long mod) {
  long long ret = 1;
  long long b = a;
  while (n) {
    if (n & 1) ret = (ret * b) % mod;
    b = (b * b) % mod;
    n >>= 1;
  }
  return (long long)ret;
}
inline void read(int &x) {
  x = 0;
  register char c = getchar();
  for (; c < '0' || c > '9'; c = getchar())
    ;
  for (; c >= '0' && c <= '9'; c = getchar())
    x = (x << 3) + (x << 1) + (c - '0');
}
inline void write(int x) {
  register char buffor[35];
  register int i = 0;
  do {
    buffor[i++] = (x % 10) + '0';
    x /= 10;
  } while (x);
  i--;
  while (i >= 0) putchar(buffor[i--]);
  putchar('\n');
}
inline int in() {
  int x;
  read(x);
  return x;
}
void solve();
int dbg = 1;
using namespace std;
int main() {
  int t = 1;
  for (int i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
int l[300005], r[300005], c[300005];
int ldp[300005], rdp[300005];
vector<int> vec;
int find(int l, int r, int a) {
  while (l < r) {
    int mi = (l + r) / 2;
    if (vec[mi] > a)
      r = mi;
    else
      l = mi + 1;
  }
  return r;
}
void solve() {
  int n, m, p1, p2, k;
  cin >> n >> m;
  p1 = p2 = k = 0;
  for (int i = 0; i < n; i++) cin >> l[i] >> r[i];
  sort(l, l + n);
  sort(r, r + n);
  for (int i = 1; i <= m; i++) {
    while (l[p1] <= i && p1 < n) k++, p1++;
    c[i - 1] = k;
    while (r[p2] <= i && p2 < n) k--, p2++;
  }
  ldp[0] = 1;
  vec.push_back(c[0]);
  for (int i = 1; i < m; i++) {
    if (vec.back() <= c[i]) {
      vec.push_back(c[i]);
      ldp[i] = vec.size();
    } else {
      int in = find(0, vec.size() - 1, c[i]);
      vec[in] = c[i];
      ldp[i] = in + 1;
    }
  }
  vec.clear();
  rdp[m - 1] = 1;
  vec.push_back(c[m - 1]);
  for (int i = m - 2; i >= 0; i--) {
    if (vec.back() <= c[i]) {
      vec.push_back(c[i]);
      rdp[i] = vec.size();
    } else {
      int in = find(0, vec.size() - 1, c[i]);
      vec[in] = c[i];
      rdp[i] = in + 1;
    }
  }
  int ans = 0;
  for (int i = 0; i < m; i++) ans = max(ans, ldp[i] + rdp[i] - 1);
  cout << ans << endl;
}
