Problem:
Score : 1000 points

Problem Statement

There are M chairs arranged in a line. The coordinate of the i-th chair (1 ≤ i ≤ M) is i.

N people of the Takahashi clan played too much games, and they are all suffering from backaches. They need to sit in chairs and rest, but they are particular about which chairs they sit in. Specifically, the i-th person wishes to sit in a chair whose coordinate is not greater than L_i, or not less than R_i. Naturally, only one person can sit in the same chair.

It may not be possible for all of them to sit in their favorite chairs, if nothing is done.
Aoki, who cares for the health of the people of the Takahashi clan, decides to provide additional chairs so that all of them can sit in chairs at their favorite positions.

Additional chairs can be placed at arbitrary real coordinates. Find the minimum required number of additional chairs.

Constraints

1 ≤ N,M ≤ 2 × 10^5

0 ≤ L_i < R_i ≤ M + 1(1 ≤ i ≤ N)

All input values are integers.

Input

Input is given from Standard Input in the following format:

N M
L_1 R_1
:
L_N R_N

Output

Print the minimum required number of additional chairs.

Sample Input 1

4 4
0 3
2 3
1 3
3 4

Sample Output 1

0

The four people can sit in chairs at the coordinates 3, 2, 1 and 4, respectively, and no more chair is needed.

Sample Input 2

7 6
0 7
1 5
3 6
2 7
1 6
2 6
3 7

Sample Output 2

2

If we place additional chairs at the coordinates 0 and 2.5, the seven people can sit at coordinates 0, 5, 3, 2, 6, 1 and 2.5, respectively.

Sample Input 3

3 1
1 2
1 2
1 2

Sample Output 3

2

Sample Input 4

6 6
1 6
1 6
1 5
1 5
2 6
2 6

Sample Output 4

2

Solution in C++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,1):0;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,1):0;}
typedef pair<int,int> P;

struct BIT {
  int n;
  vector<ll> tree;
  BIT(int n):n(n),tree(n+1) {} 
  void fill(ll val) {
    REP(i, n+1) tree[i] = (i&-i) * val;
  }
  void add(int idx, ll val) {
    for (int x=idx+1; x<=n; x+=x&-x) tree[x] += val;
  }
  ll range(int idx) {
    ll sum=0;
    for (int x=idx+1; x>0; x-=x&-x) sum += tree[x];
    return sum;
  }
  ll range(int a, int b) {
    return range(b) - range(a - 1);
  }
};


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int N = nextInt();
  int M = nextInt();

  int all = 0;
  vector<P> ps;

  int maxL = -1, minR = M+2;
  REP(i, N) {
    int L = nextInt();
    int R = nextInt();
    ps.push_back(P(L, R));
    chmax(maxL, L);
    chmin(minR, R);
  }
  sort(ALL(ps), [](const P& a, const P& b) -> bool {
    if (a.first != b.first) return a.first < b.first;
    return a.second > b.second;
  });

  BIT bit(100000 + 10);

  int ans = max(0, N - min(M, maxL + (M+1)-minR));
  for (P p : ps) {
    bit.add((M+1) - p.second, 1);
    int man = bit.range((M+1) - p.second);
    int chair = (p.first) + ((M+1) - p.second);
    int need = man - chair;
    ans = max(ans, need);
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}