#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MAXN = 200100;

int N, M;
pair <int, int> arr[MAXN];
set <int> rem;
vector <int> v[MAXN];

multiset <int> rr;

void gogo (int x)
{
    if (rem.lower_bound(x) == rem.end()) return;
    rem.erase(rem.lower_bound(x));
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> N >> M;
    for (int i = 0; i < N; i++)
    {
        cin >> arr[i].first >> arr[i].second;
        v[arr[i].first].push_back(arr[i].second);
    }

    for (int i = 1; i <= M; i++)
    {
        rem.insert(i);
    }
    for (int i = 0; i <= M; i++)
    {
        for (int j : v[i])
        {
            rr.insert(j);
        }
        while ((int) rr.size() > i)
        {
            auto it = rr.begin();
            int x = *it;
            gogo (x);
            rr.erase(it);
        }
    }

    int ans = 0;
    for (int i = M; i >= 0; i--)
    {
        if ((int) rr.size() > i)
        {
            auto it = rr.begin();
            int x = *it;
            gogo (x);
            rr.erase(it);
        }

        ans = max (ans, (int) rr.size() + min (M - i, M - (int) rem.size()));
    }
    cout << N - ans << "\n";
}