#include <bits/stdc++.h>
using namespace std;
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;
}
struct BIT {
  int n;
  vector<long long> tree;
  BIT(int n) : n(n), tree(n + 1) {}
  void fill(long long val) {
    for (int i = 0, _n = (int)(n + 1); i < _n; ++i) tree[i] = (i & -i) * val;
  }
  void add(int idx, long long val) {
    for (int x = idx + 1; x <= n; x += x & -x) tree[x] += val;
  }
  long long range(int idx) {
    long long sum = 0;
    for (int x = idx + 1; x > 0; x -= x & -x) sum += tree[x];
    return sum;
  }
  long long 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<pair<int, int> > ps;
  int maxL = -1, minR = M + 2;
  for (int i = 0, _n = (int)(N); i < _n; ++i) {
    int L = nextInt();
    int R = nextInt();
    ps.push_back(pair<int, int>(L, R));
    chmax(maxL, L);
    chmin(minR, R);
  }
  sort((ps).begin(), (ps).end(),
       [](const pair<int, int>& a, const pair<int, int>& 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 (pair<int, int> 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;
}
