#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
inline bool chmax(A &a, B b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename A, typename B>
inline bool chmin(A &a, B b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1ll << 29;
const long long MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
int N, M;
int L[212345], R[212345];
int main() {
  cin >> N >> M;
  for (int i = (0); i < (N); i++) scanf("%d %d", L + i, R + i);
  vector<pair<int, int> > v;
  int all = 0;
  for (int i = (0); i < (N); i++) {
    int long long = L[i] + 1, rr = R[i] - 1;
    if (long long > rr)
      all++;
    else
      v.push_back(pair<int, int>(-long long, rr));
  }
  int l = 1, r = M, cnt = 0;
  priority_queue<int> pq;
  for (int i = (0); i < (v.size()); i++) {
    pair<int, int> now = v[i];
    pq.push(now.second);
    if (l < -now.first) {
      l++;
      cnt++;
    } else {
      while (!pq.empty()) {
        int t = pq.top();
        pq.pop();
        if (t < r) {
          r--;
          cnt++;
          break;
        }
      }
    }
    if (cnt == M) break;
  }
  cnt = min(M, cnt + all);
  cout << max(N - cnt, 0) << endl;
  return 0;
}
