#include <bits/stdc++.h>
using namespace std;
int n, m;
bool vis[200005], ok[200005];
pair<int, int> p[200005];
inline bool cmp(pair<int, int> a, pair<int, int> b) {
  return a.second > b.second;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) scanf("%d%d", &p[i].first, &p[i].second);
  sort(p + 1, p + n + 1);
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      q;
  int now = 1;
  for (int i = 1; i <= n; ++i) {
    while (now <= m && vis[now]) ++now;
    if (now > m) break;
    vis[now] = 1;
    q.push(make_pair(p[i].second, i)), ok[i] = 1;
    if (now > p[i].first) ok[q.top().second] = 0, q.pop(), vis[now] = 0;
  }
  if (now > m) return cout << n - m, 0;
  int cnt = 0;
  for (int i = 1; i <= n; ++i)
    if (!ok[i]) p[++cnt] = p[i];
  n = cnt;
  sort(p + 1, p + n + 1, cmp);
  int res = 0;
  now = m;
  for (int i = 1; i <= n; ++i) {
    while (now && vis[now]) --now;
    if (!now) return cout << i + res << endl, 0;
    if (now >= p[i].second)
      vis[now] = 1;
    else
      ++res;
  }
  cout << res << endl;
  return 0;
}
