#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int SIZE = 1e6 + 10;
int BIT[SIZE];
void ins(int x) {
  x++;
  for (; x < SIZE; x += x & -x) BIT[x]++;
}
int qq(int x) {
  x++;
  int res = 0;
  for (; x; x -= x & -x) res += BIT[x];
  return res;
}
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  vector<pair<int, int> > pp;
  for (int i = 0; i < (N); ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    y = M + 1 - y;
    pp.push_back(make_pair(x, y));
  }
  sort((pp).begin(), (pp).end());
  int an = 0;
  for (int i = 0; i < (((int)(pp).size())); ++i) {
    int v = qq(pp[i].second);
    if (v >= pp[i].first + pp[i].second)
      an++;
    else
      ins(pp[i].second);
  }
  printf("%d\n", an);
  return 0;
}
