#include<bits/stdc++.h>
using namespace std;
//万合以致，向阳而生——背叛时代，忠于时间//
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long long ll;
 
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define forn(i, n) for(register int i=0; i<n; i++)
#define Forn(i, n) for(register int i=1; i<=n; i++)
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define Foreach(it, a) for(__typeof((a).rbegin()) it=(a).rbegin(); it!=(a).rend(); it++)
#define mid l+r>>1
#define lid id<<1|1
#define rid (id<<1)+2
#define lson lid, l, mid
#define rson rid, mid, r
 
inline int in()
{
    char c=getchar();
    int neg=1, x=0;
    while(!isdigit(c)) (c=='-')?neg=-1, c=getchar():c=getchar();
    while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48), c=getchar();
    return neg*x;
}
inline int lcm(int a, int b){return a*b/__gcd(a, b);}

const int MAX=200005;

struct dat
{
    int x, y, id;
    dat(int _x=0, int _y=0):x(_x), y(_y){}
    inline void read(int i) { id=i; x=in(), y=in(); }
    friend bool operator<(const dat&A, const dat&B) { return A.y!=B.y?A.y>B.y:A.x<B.x; }
    friend bool operator>(const dat&A, const dat&B) { return A.x!=B.x?A.x<B.x:A.y>B.y; }
    inline int valid(int p) { return p<=x||p>=y; }
}qx[MAX], qy[MAX];

int N, M, ptr, mark[MAX], lft[MAX];

inline int cmp(const dat&A, const dat&B)
{
    return A>B;
}

int main()
{
    N=in(), M=in();
    forn(i, N)
    {
        dat tmp;
        tmp.read(i);
        qx[i]=tmp;
        qy[i]=tmp;
    }
    sort(qx, qx+N, cmp);
    sort(qy, qy+N);
//    forn(i, N) cout<<qy[i].id<<" "<<qy[i].x<<" "<<qy[i].y<<endl;
    
    ptr=1;
    forn(i, N)
    {
        dat tmp=qx[i];
        if(mark[tmp.id]||ptr>tmp.x) continue;
//        cout<<tmp.id<<"x"<<ptr<<endl; 
        mark[tmp.id]=ptr;
        ptr++;
    }
    
    ptr=M;
    forn(i, N)
    {
        dat tmp=qy[i];
        
        if(ptr<tmp.y) continue;
        mark[tmp.id]=ptr;
//        cout<<tmp.id<<"y"<<ptr<<endl; 
        ptr--;
//        cout<<tmp.id<<" "<<tmp.x<<" "<<tmp.y<<endl;
    }
    int cnt=0;
    forn(i, N) if(!mark[i]) cnt++;
    printf("%d\n", cnt);
    return 0;
}