#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
const long long mod = 1000 * 1000 * 1000 + 7;
const long long p = 31;
const int INF = 1e6;
int main() {
  ios_base::sync_with_stdio(0);
  srand(555);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> v;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    tmp--;
    v.push_back({tmp, 0});
    cin >> tmp;
    tmp--;
    v.push_back({tmp, 1});
  }
  sort(v.begin(), v.end());
  vector<int> a(m, 0);
  int now = 0;
  int j = 0;
  for (int i = 0; i < m; i++) {
    while (j < v.size() && v[j].first + v[j].second == i) {
      now++;
      j++;
    }
    a[i] = now;
    while (j < v.size() && v[j].first == i) {
      now--;
      j++;
    }
  }
  vector<int> d(m + 1);
  vector<int> left(m);
  vector<int> right(m);
  d[0] = -INF;
  for (int i = 1; i <= m; ++i) d[i] = INF;
  for (int i = 0; i < m; i++) {
    int j = int(upper_bound(d.begin(), d.end(), a[i]) - d.begin());
    if (d[j - 1] <= a[i] && a[i] <= d[j]) {
      d[j] = a[i];
      left[i] = j;
    }
  }
  d.clear();
  d.resize(m + 1);
  d[0] = -INF;
  for (int i = 1; i <= m; ++i) d[i] = INF;
  for (int i = m - 1; i >= 0; i--) {
    int j = int(upper_bound(d.begin(), d.end(), a[i]) - d.begin());
    if (d[j - 1] <= a[i] && a[i] <= d[j]) {
      d[j] = a[i];
      right[i] = j;
    }
  }
  int answer = 0;
  for (int i = 0; i < m; i++) {
    answer = max(right[i] + left[i] - 1, answer);
  }
  cout << answer << endl;
}
