#include <bits/stdc++.h>
using namespace std;
int cnt[100005];
int tree[2][400005];
int ansL[100005], ansR[100005];
void update(int ind, int val, int node, int left, int right, int b) {
  if (ind < left || right < ind) return;
  if (left == right) {
    tree[b][node] = max(tree[b][node], val);
    return;
  }
  int mid = (left + right) >> 1;
  update(ind, val, node << 1, left, mid, b);
  update(ind, val, (node << 1) + 1, mid + 1, right, b);
  tree[b][node] = max(tree[b][node << 1], tree[b][(node << 1) + 1]);
}
int get(int x, int y, int node, int left, int right, int b) {
  if (y < left || right < x) return 0;
  if (x <= left && right <= y) return tree[b][node];
  int mid = (left + right) >> 1;
  return max(get(x, y, node << 1, left, mid, b),
             get(x, y, (node << 1) + 1, mid + 1, right, b));
}
int main() {
  ios::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    cnt[x]++;
    cnt[y + 1]--;
  }
  for (int i = 1; i < m; i++) cnt[i] += cnt[i - 1];
  for (int x = m - 1; x >= 0; x--) {
    int val = cnt[x];
    int tmp = 1 + get(0, val, 1, 0, m, 0);
    update(val, tmp, 1, 0, m, 0);
    ansR[x] = tmp;
  }
  for (int x = 0; x < m; x++) {
    int val = cnt[x];
    int tmp = 1 + get(0, val, 1, 0, m, 1);
    update(val, tmp, 1, 0, m, 1);
    ansL[x] = tmp;
  }
  int ans = 0;
  for (int x = 0; x < m; x++)
    if (cnt[x]) ans = max(ans, ansL[x] + ansR[x] - 1);
  cout << ans << endl;
  return 0;
}
