#include <bits/stdc++.h>
char pbuf[1 << 20], *pp1 = pbuf;
inline void push(char c) {
  *pp1 = c;
  pp1 = (pp1 - pbuf == (1 << 20) - 1) ? (fwrite(pbuf, 1, 1 << 20, stdout), pbuf)
                                      : (pp1 + 1);
}
char *p1, *p2, buf[1 << 20];
using namespace std;
inline long long rd() {
  long long ans;
  char t, k;
  while (((t = (p1 == p2 && (p1 = buf, p2 = buf + fread(buf, 1, 1 << 20, stdin),
                             p1 == p2)
                    ? 0
                    : (*(p1++)))) != '-') &&
         (t > '9' || t < '0'))
    ;
  k = (t == '-');
  ans = k ? 0 : (t - '0');
  while ((t = (p1 == p2 && (p1 = buf, p2 = buf + fread(buf, 1, 1 << 20, stdin),
                            p1 == p2)
                   ? 0
                   : (*(p1++)))) >= '0' &&
         t <= '9')
    ans = ans * 10 + t - '0';
  return k ? -ans : ans;
}
inline void wt(long long k) {
  if (k < 0)
    push('-'), wt(-k);
  else {
    if (k < 10)
      push('0' + k);
    else
      wt(k / 10), push('0' + k % 10);
  }
  return;
}
pair<int, int> a[200001];
priority_queue<int> q;
int n, m;
vector<int> v;
int main() {
  scanf("%d%d", &n, &m);
  for (register int i = (1); i <= (n); ++i)
    scanf("%d%d", &a[i].first, &a[i].second);
  sort(a + 1, a + n + 1, [&](pair<int, int> a, pair<int, int> b) {
    if (a.first == b.first) return a.second > b.second;
    return a.second < b.second;
  });
  int le = 1, ri = m;
  for (register int i = (1); i <= (n); ++i) {
    if (le > a[i].first) {
      if (q.size() && q.top() < a[i].second) {
        int t = q.top();
        q.pop();
        v.push_back(t);
      } else
        v.push_back(a[i].second);
    } else
      le++;
  }
  int Ans = 0;
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  for (int a : v) {
    if (ri < a || le > ri)
      Ans++;
    else
      ri--;
  }
  cout << Ans;
}
