#include <bits/stdc++.h>
using namespace std;
int val[100005];
int lz[400005], tree[400005];
int qian[100005], lis[100005], hou[100005];
void build(int node, int l, int r) {
  if (l == r) {
    tree[node] = 0;
    return;
  }
  int mid = (l + r) / 2;
  build(node * 2, l, mid);
  build(node * 2 + 1, mid + 1, r);
  tree[node] = tree[node * 2] + tree[node * 2 + 1];
}
void push_down(int node, int l, int r) {
  if (lz[node]) {
    int mid = (l + r) / 2;
    lz[node * 2] += lz[node];
    lz[node * 2 + 1] += lz[node];
    tree[node * 2] += (mid - l + 1) * lz[node];
    tree[node * 2 + 1] += (r - mid) * lz[node];
    lz[node] = 0;
  }
}
void update_range(int node, int l, int r, int L, int R, int add) {
  if (l <= L && r >= R) {
    lz[node] += add;
    tree[node] += (R - L + 1) * add;
    return;
  }
  push_down(node, L, R);
  int mid = (L + R) / 2;
  if (mid >= l) update_range(node * 2, l, r, L, mid, add);
  if (mid < r) update_range(node * 2 + 1, l, r, mid + 1, R, add);
  tree[node] = tree[node * 2] + tree[node * 2 + 1];
}
int query_range(int node, int L, int R, int l, int r) {
  if (l <= L && r >= R) return tree[node];
  push_down(node, L, R);
  int mid = (L + R) / 2;
  int sum = 0;
  if (mid >= l) sum += query_range(node * 2, L, mid, l, r);
  if (mid < r) sum += query_range(node * 2 + 1, mid + 1, R, l, r);
  return sum;
}
int main() {
  int n, q;
  scanf("%d%d", &q, &n);
  build(1, 1, n);
  for (int i = 1; i <= q; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    update_range(1, x, y, 1, n, 1);
  }
  for (int i = 1; i <= n; i++) {
    val[i] = query_range(1, 1, n, i, i);
  }
  qian[1] = 1;
  int len = 0;
  for (int i = 0; i <= n; i++) lis[i] = 0;
  for (int i = 1; i <= n; i++) {
    if (val[i] >= lis[len]) {
      lis[++len] = val[i];
      qian[i] = len;
    } else {
      int pos = upper_bound(lis + 1, lis + 1 + len, val[i]) - lis;
      lis[pos] = val[i];
      qian[i] = pos;
    }
  }
  len = 0;
  for (int i = 0; i <= n; i++) lis[i] = 0;
  for (int i = n; i >= 1; i--) {
    if (val[i] >= lis[len]) {
      lis[++len] = val[i];
      hou[i] = len;
    } else {
      int pos = upper_bound(lis + 1, lis + 1 + len, val[i]) - lis;
      lis[pos] = val[i];
      hou[i] = pos;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(qian[i] + hou[i] - 1, ans);
  }
  printf("%d\n", ans);
}
