#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 65;
int a[maxn];
int z[maxn];
int j[maxn];
int b[maxn];
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    a[l]++;
    a[r + 1]--;
  }
  for (int i = 1; i <= m; i++) a[i] += a[i - 1];
  memset(b, 0x3f, sizeof(b));
  b[0] = 0;
  for (int i = 1; i <= m; i++) {
    z[i] = lower_bound(b, b + m + 1, a[i] + 1) - b;
    b[z[i]] = min(b[z[i]], a[i]);
  }
  reverse(a + 1, a + 1 + m);
  memset(b, 0x3f, sizeof(b));
  b[0] = 0;
  for (int i = 1; i <= m; i++) {
    j[i] = lower_bound(b, b + m + 1, a[i] + 1) - b;
    b[j[i]] = min(b[j[i]], a[i]);
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    ans = max(ans, z[i] + j[m - i + 1] - 1);
  }
  cout << ans << endl;
}
