#include <bits/stdc++.h>
const int INF = 0x7F7F7F7F;
const double EPS = 1e-10;
const long long mod7 = 1e9 + 7;
const long long mod9 = 1e9 + 9;
using namespace std;
inline long long rit() {
  long long f = 0, key = 1;
  char c;
  do {
    c = getchar();
    if (c == '-') key = -1;
  } while (c < '0' || c > '9');
  do {
    f = f * 10 + c - '0';
    c = getchar();
  } while (c >= '0' && c <= '9');
  return f * key;
}
inline void fprt(double f) { printf("%.08lf", f); }
void init() {}
const int Z = 200005;
int n, m;
pair<int, int> p[Z];
set<int> st;
set<int>::iterator it;
int srt(pair<int, int> pa, pair<int, int> push_back) {
  if (pa.first != push_back.first) return pa.first < push_back.first;
  return pa.second > push_back.second;
}
void read() {
  n = rit(), m = rit();
  for (int i = 1; i <= m; i++) st.insert(i);
  for (int i = 0; i < n; i++) {
    p[i].first = rit(), p[i].second = rit();
  }
  sort(p, p + n, srt);
}
void solve() {
  int ans = 0;
  for (int i = 0; i < n; i++) {
    it = st.upper_bound(p[i].first);
    if (it == st.begin()) {
      it = st.lower_bound(p[i].second);
      if (it == st.end()) {
        ans++;
      } else {
        st.erase(it);
      }
    } else {
      it--;
      st.erase(it);
    }
  }
  cout << ans << endl;
}
int main() {
  int nn = 1;
  while (nn--) {
    init(), read(), solve();
  }
  return 0;
}
