#include <bits/stdc++.h>
using namespace std;
const int N = 200005, M = 100005, mod = 1e9 + 7;
template <class T>
inline void gmin(T &x, const T &y) {
  if (x > y) x = y;
}
template <class T>
inline void gmax(T &x, const T &y) {
  if (x < y) x = y;
}
inline void ch(int &x, int y) { x = (x + y) % mod; }
inline void read(int &x) {
  x = 0;
  char ch = getchar(), rev = 0;
  while (ch > '9' || ch < '0') rev = (ch == '-'), ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x = rev ? -x : x;
}
inline int exp(int x, int y) {
  int ans = 1;
  while (y) {
    if (y & 1) ans = (long long)ans * x % mod;
    x = (long long)x * x % mod;
    y >>= 1;
  }
  return ans;
}
int n, m, cnt, xx[N], yy[N], x[N], y[N];
priority_queue<int> q;
vector<int> g[N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &x[i], &y[i]), xx[i] = x[i];
    g[x[i]].push_back(y[i]);
  }
  sort(xx + 1, xx + n + 1);
  int lb = 0, ans, now;
  for (int i = 1; i <= n; i++)
    if (xx[i] > lb) lb++;
  ans = lb;
  for (int i = lb + 1; i <= m + 1; i++)
    if (g[i].size())
      for (int j : g[i]) q.push(j);
  for (int i = lb; i; i--) {
    if (g[i].size())
      for (int j : g[i]) q.push(j);
    if (!q.empty()) q.pop();
  }
  if (g[0].size())
    for (int j : g[0]) q.push(j);
  while (!q.empty()) yy[++cnt] = m + 1 - q.top(), q.pop();
  int rb = 0;
  sort(yy + 1, yy + cnt + 1);
  for (int i = 1; i <= cnt; i++)
    if (yy[i] > rb) rb++;
  printf("%d\n", n - min(n, lb + rb));
  return 0;
}
