#include <bits/stdc++.h>
using namespace std;
struct edge {
  int u, v;
  long long w;
};
const int MOD = 1e9 + 7;
double EPS = 1e-10;
int f(int H, int W, int y, int x) {
  if (y == 0) return x;
  if (x == W) return W + y;
  if (y == H) return W + H + (W - x);
  if (x == 0) return W + H + W + (H - y);
  return -1;
}
bool check(vector<int> a) {
  int N = a.size();
  if (!N) return true;
  int i0;
  for (i0 = 0; i0 < N && a[i0] != a[(i0 + 1) % N]; i0++)
    ;
  if (i0 == N) return false;
  stack<int> st;
  for (int i = 0; i < N - 2; i++) {
    int x = a[(i0 + 2 + i) % N];
    if (!st.empty() && st.top() == x)
      st.pop();
    else
      st.push(x);
  }
  return st.empty();
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> l(N), r(N);
  for (int i = 0; i < N; i++) scanf("%d%d", &l[i], &r[i]);
  vector<pair<int, int> > lr(N);
  for (int i = 0; i < N; i++) lr[i] = pair<int, int>(l[i], r[i]);
  sort(lr.rbegin(), lr.rend());
  priority_queue<int> pq;
  int i = 0, left = 0;
  vector<bool> used(M + 10);
  for (int x = M; x >= 1; x--) {
    for (; i < N && lr[i].first == x; i++) pq.push(lr[i].second);
    if (pq.size()) pq.pop(), used[x] = true, left++;
  }
  for (; i < N; i++) pq.push(lr[i].second);
  vector<int> rs;
  for (; !pq.empty(); pq.pop()) rs.push_back(pq.top());
  sort(rs.begin(), rs.end());
  int j = 0;
  int num = 0, right = 0;
  for (int x = 1; x <= M; x++) {
    for (; j < rs.size() && rs[j] == x; j++) num++;
    if (num && !used[x]) num--, right++;
  }
  cout << N - left - right << endl;
}
