#include <bits/stdc++.h>
using namespace std;
int rd(int &x) { return scanf("%d", &x); }
int rd(int &x, int &y) { return scanf("%d %d", &x, &y); }
int rd(int &x, int &y, int &z) { return scanf("%d %d %d", &x, &y, &z); }
int rd(int &x, int &y, int &z, int &s) {
  return scanf("%d %d %d %d", &x, &y, &z, &s);
}
void shaon() { cerr << endl; }
template <typename T, typename... north>
void shaon(T arg, const north &...rest) {
  cerr << arg << ' ';
  shaon(rest...);
}
const int N = 1e5 + 5;
int n, m, res;
int cnt[N], cuSum1[N], cuSum2[N];
vector<int> ans;
int main() {
  rd(n, m);
  for (int i = 1; i <= (n); i++) {
    int x, y;
    rd(x, y);
    cnt[x]++, cnt[y + 1]--;
  }
  for (int i = 1; i <= m; i++) {
    cnt[i] += cnt[i - 1];
  }
  if (m == 1) return !printf("1");
  vector<int> ans;
  for (int i = 1; i <= m; i++) {
    int pos = upper_bound(ans.begin(), ans.end(), cnt[i]) - ans.begin();
    if (pos == ans.size())
      ans.push_back(cnt[i]);
    else
      ans[pos] = cnt[i];
    cuSum1[i] = pos + 1;
  }
  ans.clear();
  for (int i = m; i >= 1; i--) {
    int pos = upper_bound(ans.begin(), ans.end(), cnt[i]) - ans.begin();
    if (pos == ans.size())
      ans.push_back(cnt[i]);
    else
      ans[pos] = cnt[i];
    cuSum2[i] = pos + 1;
  }
  for (int i = 1; i < m; i++) {
    res = max(res, cuSum1[i] + cuSum2[i + 1]);
  }
  cout << int(res);
  return 0;
}
