#include <bits/stdc++.h>

using namespace std;

const int N = 200 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n, m;
vector<int> rs[N];

bool read() {
    if (!(cin >> n >> m))
        return false;

    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        rs[a].emplace_back(b);
    }

    return true;
}

int solve() {
    auto cmp = [](const pair<int, int>& a, const pair<int, int>& b) { return a.first > b.first; };
    multiset< pair<int, int>, decltype(cmp)> ms1(cmp);
    multiset<int> ms2;

    for (auto r : rs[0])
        ms2.insert(r);

    for (int i = 1; i <= m; ++i)
        for (auto r : rs[i])
            ms1.insert(pair{r, i});

    int ans = 0;

    for (int i = 1; i <= m; ++i) {
        if (!ms1.empty()) {
            ms1.erase(ms1.begin());
            ++ans;
        } else if (!ms2.empty() && *ms2.begin() <= i) {
            ms2.erase(ms2.begin());
            ++ans;
        }

        for (auto r : rs[i]) {
            auto it = ms1.find(pair{r, i});

            if (it != ms1.end()) {
                ms1.erase(it);
                ms2.insert(r);
            }
        }
    }

    cout << n - ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}

