#include <bits/stdc++.h>
using namespace std;
struct rec {
  int l, r;
};
int i, j, m, n, x, y, start[100005], ter[100005], a[100005];
int maxi[400005], ansleft[100005], ansright[100005], temp, ans;
rec tree[400005];
int getmax(int a, int b) {
  if (a < b)
    return b;
  else
    return a;
}
void build(int rt, int l, int r) {
  tree[rt].l = l;
  tree[rt].r = r;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
}
void update(int rt, int l, int c) {
  if (tree[rt].l == tree[rt].r) {
    maxi[rt] = c;
    return;
  }
  int mid = (tree[rt].l + tree[rt].r) >> 1;
  if (l <= mid)
    update(rt << 1, l, c);
  else
    update(rt << 1 | 1, l, c);
  maxi[rt] = getmax(maxi[rt << 1], maxi[rt << 1 | 1]);
}
int query(int rt, int l, int r) {
  if ((tree[rt].l == l) && (tree[rt].r == r)) {
    return maxi[rt];
  }
  int mid = (tree[rt].l + tree[rt].r) >> 1;
  if (r <= mid) {
    return query(rt << 1, l, r);
  } else if (l > mid) {
    return query(rt << 1 | 1, l, r);
  } else {
    return getmax(query(rt << 1, l, mid), query(rt << 1 | 1, mid + 1, r));
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%d%d", &x, &y);
    start[x]++;
    ter[y]++;
  }
  for (i = 1; i <= m; i++) {
    a[i] = a[i - 1] + start[i] - ter[i - 1];
  }
  build(1, 0, n);
  for (i = 1; i <= m; i++) {
    temp = query(1, 0, a[i]);
    ansleft[i] = temp + 1;
    update(1, a[i], temp + 1);
  }
  memset(maxi, 0, sizeof(maxi));
  for (i = m; i >= 1; i--) {
    temp = query(1, 0, a[i]);
    ansright[i] = temp + 1;
    update(1, a[i], temp + 1);
  }
  for (i = 1; i <= m; i++) {
    if (ansleft[i] + ansright[i] - 1 > ans) ans = ansleft[i] + ansright[i] - 1;
  }
  printf("%d\n", ans);
  return 0;
}
