#include <bits/stdc++.h>
using namespace std;
int64_t solve(int m, const vector<int>& ls, const vector<int>& rs) {
  int n = ls.size();
  int num_nodes = n + m + 2;
  vector<vector<pair<int, int>>> e(num_nodes);
  vector<vector<int>> c(num_nodes);
  int s = 0;
  int t = 1 + n + m;
  for (int i = 0; i < n; ++i) {
    auto node = i + 1;
    e[s].emplace_back(node, e[node].size());
    c[s].push_back(1);
    e[node].emplace_back(s, e[s].size() - 1);
    c[node].push_back(0);
  }
  for (int i = 0; i < n; ++i) {
    auto node = i + 1;
    for (int j = 1; j <= ls[i]; ++j) {
      auto node2 = n + j;
      e[node].emplace_back(node2, e[node2].size());
      c[node].push_back(1);
      e[node2].emplace_back(node, e[node].size() - 1);
      c[node2].push_back(0);
    }
    for (int j = rs[i]; j <= m; ++j) {
      auto node2 = n + j;
      e[node].emplace_back(node2, e[node2].size());
      c[node].push_back(1);
      e[node2].emplace_back(node2, e[node].size() - 1);
      c[node2].push_back(0);
    }
  }
  for (int i = 1; i <= m; ++i) {
    auto node = n + i;
    e[node].emplace_back(t, e[t].size());
    c[node].push_back(1);
    e[t].emplace_back(node, e[node].size() - 1);
    c[t].push_back(0);
  }
  int f = 0;
  while (true) {
    queue<int> q;
    vector<pair<int, int>> p(num_nodes, {-1, -1});
    vector<bool> visited(num_nodes, false);
    q.push(s);
    p[s] = {-2, -2};
    visited[s] = true;
    while (!q.empty()) {
      auto d = q.front();
      if (d == t) {
        break;
      }
      q.pop();
      for (int i = 0; i < e[d].size(); ++i) {
        const auto& ee = e[d][i];
        if (c[d][i] <= 0) {
          continue;
        }
        auto a = ee.first;
        if (visited[a]) {
          continue;
        }
        p[a] = {d, i};
        q.push(a);
        visited[a] = true;
      }
    }
    if (q.empty()) {
      break;
    }
    auto cur = t;
    while (p[cur].first >= 0) {
      auto pp = p[cur].first;
      auto ll = p[cur].second;
      auto rr = e[pp][ll].second;
      c[pp][ll] -= 1;
      c[cur][rr] += 1;
      cur = pp;
    }
    ++f;
  }
  return n - f;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ls(n), rs(n);
  for (int i = 0; i < n; ++i) {
    cin >> ls[i] >> rs[i];
  }
  cout << solve(m, ls, rs) << endl;
  return 0;
}
