#include <bits/stdc++.h>
using namespace std;
vector<long long> segmax(4 * 200010, 0);
vector<long long> final;
long long buildmax(long long curr, long long st, long long end) {
  if (st == end) {
    segmax[curr] = final[st];
    return final[st];
  }
  long long mid = (st + end) / 2;
  segmax[curr] = max(buildmax(curr * 2 + 1, st, mid),
                     buildmax(curr * 2 + 2, mid + 1, end));
  return segmax[curr];
}
void updatemax(long long curr, long long st, long long end, long long ind,
               long long value) {
  if (st == end) {
    segmax[curr] = value;
    return;
  }
  long long mid = (st + end) / 2;
  if (ind <= mid) {
    updatemax(curr * 2 + 1, st, mid, ind, value);
    segmax[curr] = max(segmax[curr * 2 + 1], segmax[curr * 2 + 2]);
    return;
  } else {
    updatemax(curr * 2 + 2, mid + 1, end, ind, value);
    segmax[curr] = max(segmax[(curr * 2) + 1], segmax[(curr * 2) + 2]);
    return;
  }
}
long long querymax(long long curr, long long st, long long end, long long l,
                   long long r) {
  if (st > r || end < l) {
    return 0;
  }
  if (l <= st && end <= r) {
    return segmax[curr];
  }
  long long mid = (st + end) / 2;
  return max(querymax(curr * 2 + 1, st, mid, l, r),
             querymax(curr * 2 + 2, mid + 1, end, l, r));
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  vector<long long> pre(m + 5, 0);
  for (long long i = 0; i < n; i++) {
    long long l, r;
    cin >> l >> r;
    pre[l]++;
    pre[r + 1]--;
  }
  for (long long i = 1; i <= m; i++) {
    pre[i] += pre[i - 1];
  }
  for (long long i = 1; i <= m; i++) {
    final.push_back(pre[i]);
  }
  vector<long long> ans1;
  m = m + 5;
  for (long long i = 0; i < final.size(); i++) {
    long long curr = querymax(0, 0, m, 0, final[i]);
    curr++;
    ans1.push_back(curr);
    updatemax(0, 0, m, final[i], curr);
  }
  segmax.assign(4 * 200010, 0);
  reverse(final.begin(), final.end());
  vector<long long> ans2;
  for (long long i = 0; i < final.size(); i++) {
    long long curr = querymax(0, 0, m, 0, final[i]);
    curr++;
    ans2.push_back(curr);
    updatemax(0, 0, m, final[i], curr);
  }
  reverse(final.begin(), final.end());
  reverse(ans2.begin(), ans2.end());
  long long ans = ans1.back();
  for (long long i = 1; i < ans1.size(); i++) {
    ans = max(ans, ans1[i] + ans2[i] - 1);
  }
  cout << ans;
}
