#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int t[maxn * 4];
int tdp[2][maxn];
int dp[maxn];
void change(int L, int R, int l, int r, int rt) {
  if (L == l && R == r) {
    t[rt]++;
    return;
  }
  int mid = (l + r) / 2;
  if (R <= mid)
    change(L, R, l, mid, rt << 1);
  else if (L > mid)
    change(L, R, mid + 1, r, rt << 1 | 1);
  else {
    change(L, mid, l, mid, rt << 1);
    change(mid + 1, R, mid + 1, r, rt << 1 | 1);
  }
}
int query(int L, int R, int l, int r, int rt) {
  int sum = t[rt];
  int mid = (l + r) / 2;
  if (L == l && R == r)
    ;
  else if (R <= mid)
    sum += query(L, R, l, mid, rt << 1);
  else if (L > mid)
    sum += query(L, R, mid + 1, r, rt << 1 | 1);
  else {
    sum += query(L, mid, l, mid, rt << 1);
    sum += query(mid + 1, R, mid + 1, r, rt << 1 | 1);
  }
  return sum;
}
int a[maxn];
int bsearch(int len, int x) {
  int l = 0, r = len - 1;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (x >= dp[mid - 1] && x < dp[mid])
      return mid;
    else if (x < dp[mid - 1])
      r = mid - 1;
    else
      l = mid + 1;
  }
  return l;
}
void LIS(int n) {
  memset(dp, 0, sizeof(dp));
  dp[0] = a[0];
  tdp[0][0] = 1;
  int len = 1;
  int j;
  for (int i = 1; i < n; i++) {
    if (a[i] < dp[0])
      j = 0;
    else if (a[i] >= dp[len - 1])
      j = len++;
    else
      j = bsearch(len, a[i]);
    dp[j] = a[i];
    tdp[0][i] = len;
  }
  memset(dp, 0, sizeof(dp));
  len = 1;
  dp[0] = a[n - 1];
  tdp[1][0] = 1;
  for (int i = n - 2; i >= 0; i--) {
    if (a[i] < dp[0])
      j = 0;
    else if (a[i] >= dp[len - 1])
      j = len++;
    else
      j = bsearch(len, a[i]);
    dp[j] = a[i];
    tdp[1][i] = len;
  }
}
void solve() {
  int n, m;
  cin >> n >> m;
  memset(t, 0, sizeof(t));
  for (int i = 1, l, r; i <= n; i++) {
    scanf("%d%d", &l, &r);
    change(l, r, 1, maxn, 1);
  }
  for (int i = 1; i <= m; i++) {
    a[i - 1] = query(i, i, 1, maxn, 1);
  }
  memset(tdp, 0, sizeof(tdp));
  memset(dp, 0, sizeof(dp));
  LIS(m);
  int ans = 0;
  for (int i = 0; i < m; i++) {
    ans = max(ans, tdp[0][i] + tdp[1][i] - 1);
  }
  cout << ans << endl;
}
int main() {
  solve();
  int MARKEOF;
  if (scanf("%d", &MARKEOF))
    ;
  return 0;
}
