#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

int n,m;
vector<int> l,r;
int match[200000];
bool used[200000];

bool dfs(int v){
  for(int i = 1;i <= l[v];i++){
    int w = match[u];
    if(w < 0){
      match[i] = v;
      return true;
    }
    if(!used[i]){
      used[i] = true;
      bool f = dfs(w);
      used[i] = false;
      if(f){
        match[i] = v;
        return true;
      }
    }
  }
  for(int i = r[v];i <= m;i++){
    int w = match[u];
    if(w < 0){
      match[i] = v;
      return true;
    }
    if(!used[i]){
      used[i] = true;
      bool f = dfs(w);
      used[i] = false;
      if(f){
        match[i] = 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;
}
