#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, m;
struct qq {
  int x, y;
} s[N];
int ans = 0;
bool cmp(qq x, qq y) { return x.y < y.y; }
struct qt {
  int l, r;
  int s1, s2;
  int c;
  int lzy;
} tr[N * 2];
int num;
void update(int now) {
  int s1 = tr[now].s1, s2 = tr[now].s2;
  tr[now].c = max(tr[s1].c, tr[s2].c);
}
void bt(int l, int r) {
  int a = ++num;
  tr[a].l = l;
  tr[a].r = r;
  if (l == r) {
    tr[a].c = l;
    return;
  }
  int mid = (l + r) >> 1;
  tr[a].s1 = num + 1;
  bt(l, mid);
  tr[a].s2 = num + 1;
  bt(mid + 1, r);
  update(a);
}
void push_down(int now) {
  int s1 = tr[now].s1, s2 = tr[now].s2;
  int lzy = tr[now].lzy;
  tr[now].lzy = 0;
  tr[s1].lzy += lzy;
  tr[s1].c += lzy;
  tr[s2].lzy += lzy;
  tr[s2].c += lzy;
}
void change(int now, int l, int r, int x) {
  if (l > r) return;
  if (tr[now].l == l && tr[now].r == r) {
    tr[now].lzy += x;
    tr[now].c += x;
    return;
  }
  push_down(now);
  int s1 = tr[now].s1, s2 = tr[now].s2;
  int mid = (tr[now].l + tr[now].r) >> 1;
  if (r <= mid)
    change(s1, l, r, x);
  else if (l > mid)
    change(s2, l, r, x);
  else
    change(s1, l, mid, x), change(s2, mid + 1, r, x);
  update(now);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int u = 1; u <= n; u++) scanf("%d%d", &s[u].y, &s[u].x);
  sort(s + 1, s + 1 + n, cmp);
  bt(0, m + 1);
  int now = 1;
  for (int u = 1; u <= m; u++) {
    while (now <= n && s[now].y <= u) {
      change(1, 1, s[now].x, 1);
      now++;
    }
    ans = max(ans, -m - u - 1 + tr[1].c);
  }
  printf("%d\n", max(ans, n - m));
  return 0;
}
