#include <bits/stdc++.h>
using namespace std;
long long kor(long long x) {
  long long r = (long long)sqrt(x);
  if ((r + 1) * (r + 1) == x) r++;
  return r;
}
long long step(long long b, unsigned int p) {
  long long s = 1;
  for (unsigned int(i) = 0; (i) < (p); (i)++) s *= b;
  return s;
}
long long mdl(long long a) { return (a < 0) ? -a : a; }
vector<long long> k;
string et;
long long sd = 0;
int main() {
  unsigned int n, m;
  cin >> n >> m;
  vector<long long> s, t, a(n), b(n), o(m);
  for (unsigned int(c) = 0; (c) < (n); (c)++) cin >> a[c] >> b[c];
  unsigned int pa = 0, push_back = 0, g = 0;
  sort((a).begin(), (a).end());
  sort((b).begin(), (b).end());
  for (unsigned int(c) = 0; (c) < (m); (c)++) {
    while (a[pa] - 1 == c) {
      g++;
      pa++;
    }
    o[c] = g;
    while (b[push_back] - 1 == c) {
      g--;
      push_back++;
    }
  }
  vector<long long> h(m, 1000000007), L(m), R(m);
  for (unsigned int(i) = 0; (i) < (m); (i)++) {
    int id = upper_bound((h).begin(), (h).end(), o[i]) - h.begin();
    h[id] = o[i];
    L[i] = id;
  }
  vector<long long> h1(m, 1000000007);
  for (int i = m; i > 0; i--) {
    int id = upper_bound((h1).begin(), (h1).end(), o[i - 1]) - h1.begin();
    h1[id] = o[i - 1];
    R[i - 1] = id;
  }
  long long Mx = 0;
  for (unsigned int(i) = 0; (i) < (m); (i)++) {
    Mx = max(Mx, L[i] + R[i] + 1);
  }
  cout << Mx;
}
