#include <bits/stdc++.h>
using ld = long double;
using namespace std;
const double eps = (1e-11);
const int INF = 2e9 + 9;
const int logn = 21;
const double pi = acos(-1.0);
int pp = 1000000007;
struct Edge {
  int from, to;
  long long cap, flow;
};
struct Dinic {
  int n, tmp, s, t;
  vector<Edge> edges;
  vector<int> G[500005];
  bool vis[500005];
  int d[500005];
  int cur[500005];
  void init(int n, int s, int t) {
    this->n = n, this->s = s, this->t = t;
    edges.clear();
    for (int i = 1; i <= n; i++) G[i].clear();
  }
  void AddEdge(int from, int to, long long cap) {
    edges.push_back({from, to, cap, 0});
    edges.push_back({to, from, 0, 0});
    tmp = edges.size();
    G[from].push_back(tmp - 2);
    G[to].push_back(tmp - 1);
  }
  bool BFS() {
    memset(vis, 0, sizeof(vis));
    queue<int> q;
    q.push(s);
    d[s] = 0, vis[s] = 1;
    while (!q.empty()) {
      int x = q.front();
      q.pop();
      for (int i = 0; i < G[x].size(); i++) {
        Edge& e = edges[G[x][i]];
        if (!vis[e.to] && e.cap > e.flow) {
          vis[e.to] = 1;
          d[e.to] = d[x] + 1;
          q.push(e.to);
        }
      }
    }
    return vis[t];
  }
  long long DFS(int x, long long a) {
    if (x == t || a == 0) return a;
    long long flow = 0, f;
    for (int& i = cur[x]; i < G[x].size(); i++) {
      Edge& e = edges[G[x][i]];
      if (d[x] + 1 == d[e.to] && (f = DFS(e.to, min(a, e.cap - e.flow))) > 0) {
        e.flow += f;
        edges[G[x][i] ^ 1].flow -= f;
        flow += f;
        a -= f;
        if (a == 0) break;
      }
    }
    return flow;
  }
  long long Maxflow() {
    long long flow = 0;
    while (BFS()) {
      memset(cur, 0, sizeof(cur));
      flow += DFS(s, INF);
    }
    return flow;
  }
} dc;
signed main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int s = m + n + 1;
  int t = m + n + 2;
  dc.init(m + n + 2, s, t);
  for (int i = 1; i <= n; i++) {
    dc.AddEdge(s, i, 1);
  }
  for (int j = 1; j <= m; j++) {
    dc.AddEdge(j + n, t, 1);
  }
  for (int i = 1; i <= n; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    for (int j = 1; j <= l; j++) {
      dc.AddEdge(i, n + j, 1);
    }
    for (int j = r; j <= m; j++) {
      dc.AddEdge(i, n + j, 1);
    }
  }
  int ans = dc.Maxflow();
  printf("%d", n - ans);
  return 0;
}
