#include <bits/stdc++.h>
template <class T>
struct FlowBase {
  FlowBase(unsigned t, T u, unsigned r) : t(t), u(u), r(r) {}
  unsigned t;
  T u;
  unsigned r;
};
template <class T>
void add_edge(std::vector<std::vector<FlowBase<T>>> &graph, unsigned s,
              unsigned t, T u) {
  graph[s].push_back(FlowBase<T>(t, u, graph[t].size()));
  graph[t].push_back(FlowBase<T>(s, 0, graph[s].size() - 1));
}
template <class T, class V>
void dinic_bfs(std::vector<std::vector<V>> &graph, std::vector<int> &level,
               unsigned s) {
  std::fill(level.begin(), level.end(), static_cast<T>(-1));
  std::queue<unsigned> que;
  level[s] = 0;
  que.push(s);
  while (!que.empty()) {
    auto v = que.front();
    que.pop();
    for (auto &e : graph[v]) {
      if (e.u > 0 && level[e.t] < 0) {
        level[e.t] = level[v] + 1;
        que.push(e.t);
      }
    }
  }
};
template <class T, class V>
T dinic_dfs(std::vector<std::vector<V>> &graph, std::vector<int> &level,
            std::vector<unsigned> &iter, unsigned s, unsigned t, T f) {
  if (s == t) {
    return f;
  }
  for (auto &i = iter[s]; i < graph[s].size(); ++i) {
    auto &e = graph[s][i];
    if (e.u > 0 && level[s] < level[e.t]) {
      T d = dinic_dfs(graph, level, iter, e.t, t, std::min(f, e.u));
      if (d > 0) {
        e.u -= d;
        graph[e.t][e.r].u += d;
        return d;
      }
    }
  }
  return static_cast<T>(0);
};
template <class T, class V>
T dinic(std::vector<std::vector<V>> graph, unsigned s, unsigned t) {
  std::vector<int> level(graph.size());
  std::vector<unsigned> iter(graph.size());
  T flow = 0;
  while (true) {
    dinic_bfs<T>(graph, level, s);
    if (level[t] < 0) {
      return flow;
    }
    std::fill(iter.begin(), iter.end(), 0);
    T f;
    while ((f = dinic_dfs<T>(graph, level, iter, s, t,
                             std::numeric_limits<T>::max())) > 0) {
      flow += f;
    }
  }
};
int main() {
  unsigned N, M;
  std::cin >> N >> M;
  std::vector<std::vector<FlowBase<unsigned>>> G(N + M + 2);
  for (unsigned i = 0; i < N; ++i) {
    unsigned x, y;
    std::cin >> x >> y;
    for (unsigned j = std::max(1u, x); j <= y; ++j) {
      add_edge(G, i, N + j, 1u);
    }
  }
  for (unsigned i = N; i < N + M; ++i) {
    add_edge(G, i, N + M + 1, 1u);
  }
  for (unsigned i = 0; i < N; ++i) {
    add_edge(G, N + M, i, 1u);
  }
  unsigned x = dinic<unsigned>(G, N + M, N + M + 1);
  std::cout << N - x;
  return 0;
}
