#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> l, r;
int match[100001];
bool used[100001];
bool dfs(int v) {
  cout << v << endl;
  for (int i = 1; i <= l[v]; i++) {
    int u = i, w = match[u];
    if (w < 0) {
      match[u] = v;
      return true;
    }
    if (!used[i]) {
      used[i] = true;
      bool f = dfs(w);
      used[i] = false;
      if (f) {
        match[u] = v;
        return true;
      }
    }
  }
  for (int i = r[v]; i <= m; i++) {
    int u = i, w = match[u];
    if (w < 0) {
      match[u] = v;
      return true;
    }
    if (!used[i]) {
      used[i] = true;
      bool f = dfs(w);
      used[i] = false;
      if (f) {
        match[u] = v;
        return true;
      }
    }
  }
  return false;
}
int bipartite_matching() {
  int res = 0;
  memset(match, -1, sizeof(match));
  memset(used, 0, sizeof(used));
  for (int v = 0; v < n; v++) {
    if (dfs(v)) {
      res++;
    }
  }
  return res;
}
int i, j;
string str;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int li, ri;
    cin >> li >> ri;
    l.push_back(li);
    r.push_back(ri);
  }
  long long ans = 0;
  cout << n - bipartite_matching() << endl;
}
