#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 1, INF = 1E9 + 7;
int arr[MAX], pos_increase[MAX], pos_decrease[MAX], open[MAX], close[MAX];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> dp_up(m + 1), dp_down(m + 1);
  dp_up[0] = -INF;
  dp_down[0] = -INF;
  for (int i = 1; i <= m; i++) {
    open[i] = 0;
    close[i] = 0;
    dp_up[i] = INF;
    dp_down[i] = INF;
    pos_increase[i] = 0;
    pos_decrease[i] = 0;
    arr[i] = 0;
  }
  int a, b, last = 1;
  for (int i = 1; i <= n; i++) {
    cin >> a >> b;
    open[a]++;
    close[b]++;
  }
  int curr = 0;
  for (int i = 1; i <= m; i++) {
    curr += open[i];
    arr[i] = curr;
    curr -= close[i];
  }
  for (int i = 1; i <= m; i++) {
    int j = int(upper_bound(begin(dp_up), end(dp_up), arr[i]) - begin(dp_up));
    if (dp_up[j - 1] <= arr[i] && arr[i] < dp_up[j]) {
      dp_up[j] = arr[i];
      last = j;
      pos_increase[i] = last - 1;
    } else {
      pos_increase[i] = last;
    }
  }
  last = 1;
  for (int i = m; i >= 1; i--) {
    int j =
        int(upper_bound(begin(dp_down), end(dp_down), arr[i]) - begin(dp_down));
    if (dp_down[j - 1] <= arr[i] && arr[i] < dp_down[j]) {
      dp_down[j] = arr[i];
      last = j;
    }
    pos_decrease[i] = last;
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    ans = max(ans, pos_increase[i] + pos_decrease[i]);
  }
  cout << ans << '\n';
  return 0;
}
