#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
struct node {
  int val;
  int lazy;
} st[4 * N];
vector<int> V;
void build(int id, int l, int r) {
  if (l == r) {
    st[id].val = 0;
    V.push_back(id);
    return;
  }
  int mid = (l + r) / 2;
  build(id * 2, l, mid);
  build(id * 2 + 1, mid + 1, r);
  st[id].val = min(st[id * 2].val, st[id * 2 + 1].val);
}
void down(int id, int l, int r) {
  int t = st[id].lazy;
  st[id * 2].lazy += t;
  st[id * 2].val += t;
  st[id * 2 + 1].lazy += t;
  st[id * 2 + 1].val += t;
  st[id].lazy = 0;
}
void update(int id, int l, int r, int u, int v, int val) {
  if (v < l || r < u) {
    return;
  }
  if (u <= l && r <= v) {
    st[id].val += val;
    st[id].lazy += val;
    return;
  }
  int mid = (l + r) / 2;
  down(id, l, r);
  update(id * 2, l, mid, u, v, val);
  update(id * 2 + 1, mid + 1, r, u, v, val);
  st[id].val = min(st[id * 2].val, st[id * 2 + 1].val);
}
int get(int id, int l, int r, int u, int v) {
  if (v < l || r < u) {
    return 1000000000;
  }
  if (u <= l && r <= v) {
    return st[id].val;
  }
  int mid = (l + r) / 2;
  down(id, l, r);
  return min(get(id * 2, l, mid, u, v), get(id * 2 + 1, mid + 1, r, u, v));
}
vector<int> s, L, R;
int d[100005], e[100005], f[N], gt[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  build(1, 1, m);
  for (int i = 1; i <= n; i++) {
    int x, y;
    cin >> x >> y;
    update(1, 1, m, x, y, 1);
  }
  for (int i = 1; i <= m; i++) {
    update(1, 1, m, i, i, 0);
  }
  int M = 1000000000;
  s.push_back(0);
  for (auto i : V) s.push_back(st[i].val);
  for (int i = 1; i <= m; i++) {
    if (i == 1) {
      L.push_back(s[i]);
    } else if (L[L.size() - 1] <= s[i]) {
      L.push_back(s[i]);
    } else {
      auto it = upper_bound(L.begin(), L.end(), s[i]);
      *it = s[i];
      d[i] = it - L.begin() + 1;
      continue;
    }
    d[i] = L.size();
  }
  for (int i = 1; i <= m; i++) f[i] = s[m + 1 - i];
  L.clear();
  for (int i = 1; i <= m; i++) {
    if (i == 1) {
      L.push_back(f[i]);
    } else if (L[L.size() - 1] <= f[i]) {
      L.push_back(f[i]);
    } else {
      auto it = upper_bound(L.begin(), L.end(), f[i]);
      *it = f[i];
      e[i] = it - L.begin() + 1;
      continue;
    }
    e[i] = L.size();
  }
  int res = 0;
  for (int i = 1; i <= m; i++) {
    res = max(res, d[i] + e[m + 1 - i] - 1);
  }
  cout << res << endl;
  return 0;
}
