#include <bits/stdc++.h>
template <typename T>
void MACRO_VAR_Scan(T& t) {
  std::cin >> t;
}
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First& first, Rest&... rest) {
  std::cin >> first;
  MACRO_VAR_Scan(rest...);
}
template <typename T>
void MACRO_VEC_ROW_Init(int n, T& t) {
  t.resize(n);
}
template <typename First, typename... Rest>
void MACRO_VEC_ROW_Init(int n, First& first, Rest&... rest) {
  first.resize(n);
  MACRO_VEC_ROW_Init(n, rest...);
}
template <typename T>
void MACRO_VEC_ROW_Scan(int p, T& t) {
  std::cin >> t[p];
}
template <typename First, typename... Rest>
void MACRO_VEC_ROW_Scan(int p, First& first, Rest&... rest) {
  std::cin >> first[p];
  MACRO_VEC_ROW_Scan(p, rest...);
}
template <typename T>
inline T CHMAX(T& a, const T b) {
  return a = (a < b) ? b : a;
}
template <typename T>
inline T CHMIN(T& a, const T b) {
  return a = (a > b) ? b : a;
}
using ll = long long;
using ull = unsigned long long;
constexpr int INFINT = 1 << 30;
constexpr int INFINT_LIM = (1LL << 31) - 1;
constexpr ll INFLL = 1LL << 60;
constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62);
constexpr double EPS = 1e-7;
constexpr int MOD = 1000000007;
constexpr double PI = 3.141592653589793238462643383279;
class Dinic {
 private:
  struct Edge {
    int to, cap, rev;
    Edge(int t, int c, int r) : to(t), cap(c), rev(r) {}
  };
  int V;
  std::vector<std::vector<Edge>> graph;
  std::vector<int> level, iter;

 public:
  Dinic(int v) : V(v) {
    graph.resize(v);
    level.resize(v, -1);
    iter.resize(v, 0);
  }
  void addEdge(int from, int to, int cap) {
    graph[from].emplace_back(to, cap, graph[to].size());
    graph[to].emplace_back(from, 0, graph[from].size() - 1);
  }
  void bfs(int s) {
    std::fill(level.begin(), level.end(), -1);
    std::queue<int> queue;
    level[s] = 0;
    queue.push(s);
    while (!queue.empty()) {
      int v = queue.front();
      queue.pop();
      for (int i = 0; i < graph[v].size(); ++i) {
        Edge& e = graph[v][i];
        if (e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[v] + 1;
          queue.push(e.to);
        }
      }
    }
  }
  inline int dfs(int v, int t, int f) {
    if (v == t) return f;
    for (int& i = iter[v]; i < graph[v].size(); ++i) {
      Edge& e = graph[v][i];
      if (e.cap > 0 && level[v] < level[e.to]) {
        int d = dfs(e.to, t, std::min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          graph[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }
  int maxFlow(int s, int t) {
    int res = 0;
    while (true) {
      bfs(s);
      if (level[t] < 0) return res;
      std::fill(iter.begin(), iter.end(), 0);
      int f;
      while ((f = dfs(s, t, (1LL << 31) - 1)) > 0) {
        res += f;
      }
    }
  }
};
int pos, as;
Dinic dn = Dinic(1);
void add(int a, int b, int p, int l, int r) {
  if (r <= a || b <= l) return;
  if (a <= l && r <= b) {
    dn.addEdge(as + pos, p, 1);
  } else {
    add(a, b, 2 * p + 1, l, (l + r) / 2);
    add(a, b, 2 * p + 2, (l + r) / 2, r);
  }
};
signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  ;
  int n, m;
  MACRO_VAR_Scan(n, m);
  ;
  std::vector<int> l, r;
  MACRO_VEC_ROW_Init(n, l, r);
  for (int i = 0; i < n; ++i) {
    MACRO_VEC_ROW_Scan(i, l, r);
  };
  as = std::pow(2, std::ceil(std::log(m + 2) / std::log(2)) + 1) - 1;
  dn = Dinic(as + 2 + n);
  for (int i = 0; i < int((as + 1) / 2 - 1); ++i) {
    dn.addEdge(i, i * 2 + 1, 200005);
    dn.addEdge(i, i * 2 + 2, 200005);
  }
  for (int i = 0; i < int(m); ++i) {
    int p = (as + 1) / 2 + i;
    dn.addEdge(p, n + as + 1, 1);
  }
  for (int i = 0; i < int(n); ++i) {
    dn.addEdge(n + as, as + i, 1);
  }
  for (int i = 0; i < int(n); ++i) {
    pos = i;
    add(0, l[i] + 1, 0, 0, (as + 1) / 2);
    add(r[i], m + 2, 0, 0, (as + 1) / 2);
  }
  int t = dn.maxFlow(n + as, n + as + 1);
  std::cout << n - t;
  std::cout << "\n";
  ;
  return 0;
}
