#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
template <typename T>
using Graph = vector<vector<T>>;
template <typename T>
using Spacial = vector<vector<vector<T>>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
string interval[2] = {" ", "\n"};
template <typename T>
struct is_plural : false_type {};
template <typename T1, typename T2>
struct is_plural<pair<T1, T2>> : true_type {};
template <typename T>
struct is_plural<vector<T>> : true_type {};
template <typename T>
struct is_plural<complex<T>> : true_type {};
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
  return is >> p.first >> p.second;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  return os << p.first << " " << p.second;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto itr = vec.begin(); itr != vec.end(); ++itr) is >> *itr;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  if (vec.empty()) return os;
  bool pl = is_plural<T>();
  os << vec.front();
  for (auto itr = ++vec.begin(); itr != vec.end(); ++itr)
    os << interval[pl] << *itr;
  return os;
}
bool CoutYN(bool a, string y = "Yes", string n = "No") {
  cout << (a ? y : n) << "\n";
  return a;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}
template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}
long long modpow(int a, long long n, int mod = MOD) {
  long long ret = 1;
  do {
    if (n & 1) ret = ret * a % mod;
    a = 1LL * a * a % mod;
  } while (n >>= 1);
  return ret;
}
template <typename T>
T GCD(T a, T b) {
  return b ? GCD(b, a % b) : a;
}
template <typename T>
T LCM(T a, T b) {
  return a / GCD(a, b) * b;
}
template <typename T1, typename T2>
bool CompareBySecond(pair<T1, T2> a, pair<T1, T2> b) {
  return a.second != b.second ? a.second < b.second : a.first < b.first;
}
template <typename T1, typename T2>
bool CompareByInverse(pair<T1, T2> a, pair<T1, T2> b) {
  return a.first != b.first ? a.first < b.first : a.second > b.second;
}
template <typename Monoid>
struct SegmentTree {
  using F = function<Monoid(Monoid, Monoid)>;
  int sz;
  vector<Monoid> seg;
  const F f;
  const Monoid M1;
  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while (sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }
  void set(int k, const Monoid &x) { seg[k + sz] = x; }
  void build() {
    for (int k = sz - 1; k > 0; --k) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }
  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while (k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }
  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if (a & 1) L = f(L, seg[a++]);
      if (b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }
  Monoid operator[](const int &k) const { return seg[k + sz]; }
  template <typename C>
  int find_subtree(int a, const C &check, Monoid &M, bool type) {
    while (a < sz) {
      Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
      if (check(nxt))
        a = 2 * a + type;
      else
        M = nxt, a = 2 * a + 1 - type;
    }
    return a - sz;
  }
  template <typename C>
  int find_first(int a, const C &check) {
    Monoid L = M1;
    if (a <= 0) {
      if (check(f(L, seg[1]))) return find_subtree(1, check, L, false);
      return -1;
    }
    int b = sz;
    for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if (a & 1) {
        Monoid nxt = f(L, seg[a]);
        if (check(nxt)) return find_subtree(a, check, L, false);
        L = nxt;
        ++a;
      }
    }
    return -1;
  }
  template <typename C>
  int find_last(int b, const C &check) {
    Monoid R = M1;
    if (b >= sz) {
      if (check(f(seg[1], R))) return find_subtree(1, check, R, true);
      return -1;
    }
    int a = sz;
    for (b += sz; a < b; a >>= 1, b >>= 1) {
      if (b & 1) {
        Monoid nxt = f(seg[--b], R);
        if (check(nxt)) return find_subtree(b, check, R, true);
        R = nxt;
      }
    }
    return -1;
  }
};
void solve() {
  int n, m;
  cin >> n >> m;
  vector<pii> g;
  g.reserve(n);
  for (int i = 0; i < (int)(n); ++i) {
    int l, r;
    cin >> l >> r;
    --l, --r;
    g.emplace_back(l, r);
  }
  sort((g).begin(), (g).end(), CompareByInverse<int, int>);
  SegmentTree<bool> seg(
      m, [](bool a, bool b) { return a | b; }, false);
  for (int i = 0; i < (int)(m); ++i) seg.set(i, true);
  seg.build();
  int add = 0;
  for (auto &p : g) {
    int r = seg.find_first(p.second, [](bool b) { return b; });
    if (r != -1 && r < m) {
      seg.update(r, false);
      continue;
    }
    int l = seg.find_last(p.first + 1, [](bool b) { return b; });
    if (l != -1) {
      seg.update(l, false);
      continue;
    }
    ++add;
  }
  cout << add << endl;
}
signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  solve();
  return 0;
}
