#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  register int c = getchar();
  x = 0;
  int neg = 0;
  for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
inline void writeln(int x) {
  char buffor[21];
  register int i = 0;
  int neg = 0;
  if (x < 0) {
    neg = 1;
    x = -x;
  }
  do {
    buffor[i++] = (x % 10) + '0';
    x /= 10;
  } while (x);
  i--;
  if (neg) putchar('-');
  while (i >= 0) putchar(buffor[i--]);
  putchar('\n');
}
const int N = (int)2e5 + 10;
int n, m;
pair<int, int> p[N];
int it[4 * N], low[4 * N], high[4 * N];
void input() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> p[i].first >> p[i].second;
}
bool cmp(pair<int, int> a, pair<int, int> b) {
  return a.first > b.first or ((a.first == b.first) and (a.second > b.second));
}
void build(int x, int l, int r) {
  low[x] = l;
  high[x] = r;
  if (l == r) {
    it[x] = 1;
    return;
  }
  int m = (l + r) / 2;
  build(2 * x, l, m);
  build(2 * x + 1, m + 1, r);
  it[x] = it[2 * x] + it[2 * x + 1];
}
void update(int x, int v) {
  if (low[x] > v or high[x] < v) return;
  if (low[x] == high[x]) {
    it[x]--;
    return;
  }
  update(2 * x, v);
  update(2 * x + 1, v);
  it[x] = it[2 * x] + it[2 * x + 1];
}
int query(int x, int r) {
  if (high[x] < r or it[x] == 0) return -1;
  if (low[x] == high[x]) return low[x];
  int res = query(2 * x, r);
  if (res != -1)
    return res;
  else
    return query(2 * x + 1, r);
}
void solve() {
  sort(p + 1, p + 1 + n, cmp);
  build(1, 1, m);
  int res = 0;
  p[0].first = -1;
  p[n + 1].first = 0;
  for (int i = 1; i <= n; i++)
    if (p[i].first != p[i - 1].first) {
      int j = i;
      while (j < n and p[j + 1].first == p[i].first) j++;
      int cleft = p[i].first - p[j + 1].first;
      res += cleft;
      for (int k = p[i].first; k >= p[j + 1].first + 1; k--) update(1, k);
      for (int k = i + cleft; k <= j; k++) {
        int cright = query(1, p[k].second);
        if (cright != -1) {
          res++;
          update(1, cright);
        }
      }
    }
  cout << n - res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  input();
  solve();
  return 0;
}
