#include <bits/stdc++.h>
using namespace std;
const int N_MAX = 200005;
const int M_MAX = 200005;
int num;
vector<int> node;
vector<int> lazy;
int n, m;
void init() {
  num = 1;
  while (num < m + 1) num *= 2;
  node.assign(2 * num - 1, 0);
  lazy.assign(2 * num - 1, 0);
  for (int i = 1; i <= m; i++) {
    node[i + num - 1] = 0 + i - m - 1;
  }
  for (int k = num - 2; k >= 0; k--) {
    node[k] = max(node[2 * k + 1], node[2 * k + 2]);
  }
}
void eval(int k) {
  if (lazy[k] == 0) return;
  if (k < num - 1) {
    lazy[2 * k + 1] += lazy[k];
    lazy[2 * k + 2] += lazy[k];
  }
  node[k] += lazy[k];
  lazy[k] = 0;
}
void add_sub(int l, int r, int x, int k, int tl, int tr) {
  eval(k);
  if (r <= tl || tr <= l)
    return;
  else if (l <= tl && tr <= r) {
    lazy[k] += x;
    eval(k);
    return;
  } else {
    add_sub(l, r, x, 2 * k + 1, tl, (tl + tr) / 2);
    add_sub(l, r, x, 2 * k + 2, (tl + tr) / 2, tr);
    node[k] = max(node[2 * k + 1], node[2 * k + 2]);
  }
}
void add(int l, int r, int x) { add_sub(l, r, x, 0, 0, num); }
int find_sub(int l, int r, int k, int tl, int tr) {
  eval(k);
  if (r <= tl || tr <= l)
    return 0;
  else if (l <= tl && tr <= r)
    return node[k];
  else {
    int vl = find_sub(l, r, 2 * k + 1, tl, (tl + tr) / 2);
    int vr = find_sub(l, r, 2 * k + 2, (tl + tr) / 2, tr);
    return max(vl, vr);
  }
}
int needchair(int s) { return find_sub(s + 2, m + 1, 0, 0, num) - s; }
int main() {
  cin >> n >> m;
  vector<pair<int, int>> NEED;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    NEED.emplace_back(l, r);
  }
  init();
  sort(NEED.begin(), NEED.end());
  int ans = max(n - m, 0);
  for (int i = 0; i < NEED.size(); i++) {
    int l = NEED[i].first;
    int r = NEED[i].second;
    add(l, r + 1, 1);
    ans = max(ans, needchair(l));
  }
  cout << ans << endl;
  return 0;
}
