#include <bits/stdc++.h>

using namespace std;

//#define FILE_IO

int N, M;
int l[200005], r[200005];
int c[200005];
int ord[200005];

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d%d", &N, &M);
    for(int i = 1; i <= N; i++)
    {
        scanf("%d%d", &l[i], &r[i]);
        ord[i] = i;
    }

    int cnt = 0;

    sort(ord + 1, ord + N + 1,
         [](int a, int b) { if(l[a] == l[b]) return r[a] > r[b]; return l[a] < l[b]; } );

    int id = 1;
    for(int x = 1; x <= N; x++)
    {
        int i = ord[x];
        if(id <= l[i] && !c[i])
        {
            c[i] = id;
            id++;
            cnt++;
        }
    }

    sort(ord + 1, ord + N + 1,
         [](int a, int b) { if(r[a] == r[b]) return l[a] < l[b]; return r[a] > r[b]; } );

    int idst = id - 1;
    id = M;
    for(int x = 1; x <= N; x++)
    {
        if(idst == id)  break;
        int i = ord[x];

        if(id >= r[i] && !c[i])
        {
            c[i] = id;
            id--;
            cnt++;
        }
    }

    printf("%d\n", N - cnt);

    return 0;
}
