#include <bits/stdc++.h>
using namespace std;
const int MN = 200010;
int N, M;
vector<pair<int, int> > seg;
struct BIT {
  vector<int> tree, lazy;
  void init() {
    tree = vector<int>(4 * MN, 0);
    lazy = vector<int>(4 * MN, 0);
  }
  void prop(int l, int r, int n) {
    if (l != r) {
      tree[2 * n] += lazy[n];
      lazy[2 * n] += lazy[n];
      tree[2 * n + 1] += lazy[n];
      lazy[2 * n + 1] += lazy[n];
      lazy[n] = 0;
    }
  }
  void upd(int a, int b, int d, int l, int r, int n) {
    if (b < l || r < a) return;
    if (a <= l && r <= b) {
      tree[n] += d;
      lazy[n] += d;
      return;
    }
    prop(l, r, n);
    int m = (l + r) >> 1;
    upd(a, b, d, l, m, 2 * n);
    upd(a, b, d, m + 1, r, 2 * n + 1);
    tree[n] = min(tree[2 * n], tree[2 * n + 1]);
  }
  int quer(int a, int b, int l, int r, int n) {
    if (b < l || r < a) return 1e9;
    if (a <= l && r <= b) return tree[n];
    prop(l, r, n);
    int m = (l + r) >> 1;
    int L = quer(a, b, l, m, 2 * n);
    int R = quer(a, b, m + 1, r, 2 * n + 1);
    return min(L, R);
  }
} bit;
int main() {
  scanf("%d %d", &N, &M);
  seg.resize(N);
  for (int i = 0; i < N; i++) {
    scanf("%d %d", &seg[i].first, &seg[i].second);
    seg[i].first--;
    seg[i].second--;
  }
  sort(seg.begin(), seg.end());
  bit.init();
  for (int i = M - 1; i >= 0; i--) {
    bit.upd(0, i, 1, 0, MN - 1, 1);
  }
  for (int i = 0; i < N; i++) {
    bit.upd(seg[i].first + 1, M, 1, 0, MN - 1, 1);
  }
  int pos = 0;
  while (pos < N && seg[pos].first == -1) {
    bit.upd(seg[pos].first + 1, seg[pos].second, -1, 0, MN - 1, 1);
    pos++;
  }
  int ans = bit.quer(0, M, 0, MN - 1, 1);
  for (int i = 0; i < M; i++) {
    while (pos < N && seg[pos].first == i) {
      bit.upd(seg[pos].first + 1, seg[pos].second, -1, 0, MN - 1, 1);
      pos++;
    }
    ans = min(ans, i + 1 + bit.quer(i + 1, M, 0, MN - 1, 1));
  }
  printf("%d", N - ans);
}
