#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int n, m, fre[N], kt[N];
typedef struct ds {
  int x, y;
};
ds a[N];
bool cmp(ds a, ds b) { return (a.x < b.x) || ((a.x == b.x) && (a.y > b.y)); }
void nhap() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i].x, &a[i].y);
  }
  fre[m + 2] = 1;
  sort(a + 1, a + 1 + n, cmp);
}
void solve() {
  int res = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i].x == 0) {
      continue;
    }
    if (fre[a[i].x - 1] == 0) {
      res++;
      kt[i] = 1;
      fre[a[i].x - 1] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (a[i].y == m + 1) {
      continue;
    }
    if (fre[a[i].y + 1] == 0 && kt[i] == 0) {
      res++;
      fre[a[i].y + 1] = 1;
    }
  }
  cout << n - res << endl;
}
int main() {
  nhap();
  solve();
}
