#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;
    dat(int _x=0, int _y=0):x(_x), y(_y){}
    inline void read() { x=in(), y=in(); }
    friend bool operator<(const dat&A, const dat&B) { A.x<B.x; }
}qx[MAX];

int N, M, ptrl, ptrr, cnt, mark[MAX];
priority_queue<int, vi, greater<int> > Q;
vi tt;

int main()
{
    N=in(), M=in();
    forn(i, N) qx[i].read();
    sort(qx, qx+N);
    ptrl=1;
    forn(i, N)
    {
        dat tmp=qx[i];
        Q.push(tmp.y);
        if(tmp.x>=ptrl&&ptrl<=M) ptrl++;
        else tt.pb(Q.top()), Q.pop();
    }
    ptrr=M;
    sort(tt.begin(), tt.end(), greater<int>());
    foreach(it, tt)
        if(*it<=ptrr&&ptrr>=ptrl) ptrr--;
        else cnt++;
    printf("%d\n", cnt);
    return 0;
}