#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = (long long)1000000007 * 1000000007;
const long double eps = 1e-11;
const long double pi = acos(-1.0);
pair<int, int> a[200000];
bool comp(pair<int, int> x, pair<int, int> y) {
  if (x.first != x.second) return x.first < y.first;
  return x.second > y.second;
}
int main() {
  int n, m;
  cin >> n >> m;
  int le = 1;
  int ri = m;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    a[i] = {x, y};
  }
  sort(a, a + n, comp);
  int out = n;
  priority_queue<int> q;
  for (int i = 0; i < n; i++) {
    if (ri < le) break;
    q.push(a[i].second);
    if (a[i].first < le) {
      while (!q.empty()) {
        int h = q.top();
        q.pop();
        if (h <= ri) {
          ri--;
          out--;
          break;
        }
      }
    } else {
      le++;
      out--;
    }
  }
  cout << out << endl;
  return 0;
}
