#include <bits/stdc++.h>
using namespace std;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vc<vc<T>>;
template <class T>
void mkuni(vector<T>& v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
template <class T>
void print(T x, int suc = 1) {
  cout << x;
  if (suc == 1)
    cout << '\n';
  else
    cout << ' ';
}
template <class T>
void print(const vector<T>& v, int suc = 1) {
  for (int i = 0; i < v.size(); i++)
    print(v[i], i == (int)(v.size()) - 1 ? suc : 2);
}
const int maxn = 2e5 + 7;
int lz[maxn << 2];
int mx[maxn << 2];
pair<int, int> seg[maxn];
vector<int> rr[maxn];
int n, m;
const int INF = 0x3f3f3f3f;
void build(int L = 0, int R = m + 1, int o = 1) {
  if (L == R) {
    mx[o] = -m + L - 1;
    return;
  }
  int mid = L + R >> 1;
  build(L, mid, o << 1);
  build(mid + 1, R, o << 1 | 1);
  mx[o] = max(mx[o << 1], mx[o << 1 | 1]);
}
inline void pushdown(int o) {
  if (lz[o]) {
    mx[o << 1] += lz[o];
    mx[o << 1 | 1] += lz[o];
    lz[o << 1] += lz[o];
    lz[o << 1 | 1] += lz[o];
    lz[o] = 0;
  }
}
void update(int l, int r, int L = 0, int R = m + 1, int o = 1) {
  if (l <= L && r >= R) {
    lz[o]++;
    mx[o]++;
    return;
  }
  pushdown(o);
  int mid = L + R >> 1;
  if (l <= mid) update(l, r, L, mid, o << 1);
  if (r > mid) update(l, r, mid + 1, R, o << 1 | 1);
  mx[o] = max(mx[o << 1], mx[o << 1 | 1]);
}
int query(int l, int r, int L = 0, int R = m + 1, int o = 1) {
  if (l <= L && r >= R) return mx[o];
  pushdown(o);
  int mid = L + R >> 1;
  int ret = -INF;
  if (l <= mid) ret = max(ret, query(l, r, L, mid, o << 1));
  if (r > mid) ret = max(ret, query(l, r, mid + 1, R, o << 1 | 1));
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> seg[i].first >> seg[i].second;
    rr[seg[i].first].push_back(seg[i].second);
  }
  build();
  int ans = 0;
  for (int i = 0; i <= m; i++) {
    for (auto u : rr[i]) update(0, u);
    ans = max(ans, -i + query(i + 1, m + 1));
  }
  cout << ans << '\n';
}
