#include <bits/stdc++.h>
using namespace std;
int a[100005], tr[100005 << 2], r[100005], l[100005];
pair<int, int> p[100005];
int kom(int n, int b, int e) {
  int m;
  while (b < e) {
    m = (b + e + 1) >> 1;
    if (r[m] < n)
      b = m;
    else
      e = m - 1;
  }
  if (r[b] >= n) return b - 1;
  return b;
}
int besi(int n, int b, int e) {
  int m;
  while (b < e) {
    m = (b + e) >> 1;
    if (l[m] > n)
      e = m;
    else
      b = m + 1;
  }
  if (l[b] <= n) return b + 1;
  return b;
}
int get(int n, int b, int e, int i, int j) {
  if (j < b || e < i || i > j) return 0;
  if (i <= b && j >= e) return tr[n];
  int l, r, m;
  m = (b + e) >> 1;
  l = n << 1;
  r = l + 1;
  return max(get(l, b, m, i, j), get(r, m + 1, e, i, j));
}
void udpate(int n, int b, int e, int i, int v) {
  if (i < b || i > e) return;
  if (b == e) {
    tr[n] = v;
    return;
  }
  int l, r, m;
  m = (b + e) >> 1;
  l = n << 1;
  r = l + 1;
  udpate(l, b, m, i, v);
  udpate(r, m + 1, e, i, v);
  tr[n] = max(tr[l], tr[r]);
}
void init(int n, int b, int e) {
  tr[n] = 0;
  if (b == e) return;
  int l, r, m;
  m = (b + e) >> 1;
  l = n << 1;
  r = l + 1;
  init(l, b, m);
  init(r, m + 1, e);
}
bool cmp1(pair<int, int> a, pair<int, int> b) {
  if (a.first == b.first) return (a.second < b.second);
  return (a.first < b.first);
}
bool cmp2(pair<int, int> a, pair<int, int> b) {
  if (a.first == b.first) return (a.second > b.second);
  return (a.first < b.first);
}
int main() {
  int n, m, ans;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &l[i], &r[i]);
  }
  sort(l, l + n);
  sort(r, r + n);
  for (int i = 1; i <= m; i++) {
    a[i] = -kom(i, 0, n - 1) - 1 + besi(i, 0, n - 1);
    p[i] = make_pair(a[i], i);
  }
  sort(p + 1, p + 1 + m, cmp1);
  ans = 0;
  for (int i = 1; i <= m; i++) {
    n = get(1, 1, m, 1, p[i].second - 1);
    udpate(1, 1, m, p[i].second, n + 1);
    a[p[i].second] = n + 1;
  }
  init(1, 1, m);
  sort(p + 1, p + 1 + m, cmp2);
  for (int i = 1; i <= m; i++) {
    n = get(1, 1, m, p[i].second + 1, m);
    udpate(1, 1, m, p[i].second, n + 1);
    ans = max(ans, a[p[i].second] + n);
  }
  printf("%d\n", ans);
  return 0;
}
