#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const int INF = 0x3f3f3f3f;
const int iinf = 1 << 30;
const long long linf = 2e18;
const int mod = 1000000007;
const double eps = 1e-7;
void douout(double x) { printf("%lf\n", x + 0.0000000001); }
template <class T>
void print(T a) {
  cout << a << endl;
  exit(0);
}
template <class T>
void chmin(T &a, T b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, T b) {
  if (a < b) a = b;
}
void add(int &a, int b) { a = a + b < mod ? a + b : a + b - mod; }
void sub(int &a, int b) { a = (a - b + mod) % mod; }
void mul(int &a, int b) { a = (long long)a * b % mod; }
int addv(int a, int b) { return (a += b) >= mod ? a -= mod : a; }
int subv(int a, int b) { return (a -= b) < 0 ? a += mod : a; }
int mulv(int a, int b) { return (long long)a * b % mod; }
int read() {
  int f = 1, x = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int pw(int a, int b) {
  int s = 1;
  for (; b; b >>= 1, a = (long long)a * a % mod)
    if (b & 1) s = (long long)s * a % mod;
  return s;
}
int n, m, ans;
vector<int> tmp;
struct point {
  int l, r;
  bool operator<(const point &a) const { return l != a.l ? l < a.l : r < a.r; }
} a[N];
priority_queue<int, vector<int>, greater<int> > q;
signed main() {
  scanf("%d%d", &n, &m);
  for (int i = (1); i <= (n); i++) scanf("%d%d", &a[i].l, &a[i].r);
  sort(a + 1, a + n + 1);
  int hd = 1, tl = m;
  for (int i = (1); i <= (n); i++) {
    q.push(a[i].r);
    if (hd <= tl && hd <= a[i].l)
      hd++;
    else {
      tmp.push_back(q.top());
      q.pop();
    }
  }
  sort(tmp.begin(), tmp.end());
  for (int i = (((int)tmp.size()) - 1); i >= (0); i--) {
    if (hd <= tl && tmp[i] <= tl)
      tl--;
    else
      ans++;
  }
  printf("%d\n", ans);
  return 0;
}
