#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 100 + 10;
const int MAX_X = 1000 + 20;
const int MAX_N = 100 + 20;
const int MOD = 1000 * 1000 * 1000 + 7;
const int INF = 1000 * 1000 * 1000 + 1;
int poww(int x, int y) {
  return (!y ? 1 : (y & 1 ? x * poww(x * x, y / 2) : poww(x * x, y / 2)));
}
long long t[N * 4];
long long tdp[2][N];
long long dp[N];
void change(long long L, long long R, long long l, long long r, long long 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);
  }
}
long long query(long long L, long long R, long long l, long long r,
                long long rt) {
  long long sum = t[rt];
  long long 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[N];
int bs(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 = bs(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 = bs(len, a[i]);
    dp[j] = a[i];
    tdp[1][i] = len;
  }
}
long long n, m;
void input() {
  cin >> n >> m;
  memset(t, 0, sizeof(t));
  for (int i = 1; i <= n; i++) {
    long long l, r;
    cin >> l >> r;
    change(l, r, 1, N, 1);
  }
  for (int i = 1; i <= m; i++) a[i - 1] = query(i, i, 1, N, 1);
}
void solve() {
  memset(tdp, 0, sizeof(tdp));
  memset(dp, 0, sizeof(dp));
  LIS(m);
  long long ans = 0;
  for (int i = 0; i < m; i++) ans = max(ans, tdp[0][i] + tdp[1][i] - 1);
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cout.tie(0);
  input();
  solve();
  return 0;
}
