#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long long llong;
typedef long double ld;

using namespace std;

template <typename T> void dprint(T begin, T end) {
    for (auto i = begin; i != end; i++) {
        cerr << (*i) << " ";
    }
    cerr << "\n";
}

multiset<int> ss;
int n, m;
int l, r;
vector<int> go[210000];

int main() {
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> r >> l;
        go[l].push_back(r);
    }
    int ans = 0;
    for (int it = 0; it < 5; ++it) {
        for (int i = 0; i <= m + 1; ++i) {
            for (int j: go[i])
                ss.insert(j);
            go[i].clear();
            if (i >= 1 && i <= m) {
                auto it = ss.lower_bound(i);
                int x = -1;
                if (it != ss.end()) {
                    x = *it;
                }
                else if (!ss.empty()) {
                    x = *ss.begin();
                    it = ss.begin();
                }
                if (x != -1) {
                    go[i].push_back(x);
                    ss.erase(it);
                }
            }
            ans += ss.count(i);
            ss.erase(i);
        }
    }
    ans += ss.size();
    cout << ans << "\n";
    return 0;
}


