#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

#define MAXN 200009

int l[MAXN], r[MAXN];

vector <int> v[MAXN];

int ult[MAXN];

int unde[MAXN], cine[MAXN];

struct lex_compare {
    bool operator () (const int &x, const int &y) const {
        return r[x] > r[y];
    }
};

multiset <int, lex_compare> s;

int main() {
    int n, m;
    cin >> n >> m;

    for (int i = 1; i <= n; i++)
        cin >> l[i] >> r[i];

    for (int i = 1; i <= n; i++)
        v[l[i]].push_back(i);

    for (int i = m; i > 0; i--) {
        for (auto &x : v[i])
            s.insert(x);

        if(!s.empty()) {
            int x = *(s.begin());
            s.erase(s.begin());

            cine[i] = x;
            unde[x] = i;
        }
    }

    int rest = 0;
    for (int i = 1; i <= m; i++) {
        if(cine[i]) {
            int x = cine[i];
            cine[i] = 0;
            unde[x] = i - rest;
            cine[unde[x]] = x;
        }else rest++;
    }

    int q = 0;
    for (int i = 1; i <= n; i++)
        if(unde[i] == 0)
            ult[++q] = r[i];

    std::sort(ult + 1, ult + q +1);

    int poz = 1;
    for (int i = 1; i <= m; i++)
        if(poz <= q && ult[poz] <= i && cine[i] == 0)
            poz++;

    int ans = q - poz + 1;
    cout << ans;

    return 0;
}
