#include <bits/stdc++.h>
using namespace std;
struct P {
  int x, y, z;
  bool operator<(const P &a) const { return y > a.y; };
};
int a, b, c, d, i, k, n, m, e, dx[10] = {1, 0, -1, 0, 1, 1, -1, -1},
                               dy[10] = {0, 1, 0, -1, 1, -1, 1, -1};
long long o[500101];
int l[500111];
int j[201001];
long long x, y, z, mod = 998244353;
string r;
P u[500101];
priority_queue<int, vector<int>, greater<int> > q;
stack<int> s;
map<int, int> p;
vector<int> v;
bool as(P a, P b) {
  if (a.x != b.x) return a.x < b.x;
  return a.y > b.y;
}
int main() {
  scanf("%d %d", &a, &b);
  for (int t = 1; t <= a; t++) {
    scanf("%d %d", &n, &m);
    u[t] = {n, m};
  }
  sort(u + 1, u + a + 1, as);
  for (int t = 1; t <= a; t++) {
    q.push(u[t].y);
    for (; q.size() > u[t].x; q.pop()) o[q.top()]++;
  }
  for (int t = 1; t <= b; t++) {
    o[b - t + 1] += o[b - t + 2];
    for (; o[b - t + 1] > t; o[b - t + 1]--, k++)
      ;
  }
  printf("%d", k);
}
