#include <bits/stdc++.h>
using namespace std;
int in() {
  int x;
  scanf("%d", &x);
  return x;
}
long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
struct SqrtDecomposition2 {
  const long long INF = 1e18;
  int n, sqrtn, k;
  vector<long long> dat, buk, lazy;
  vector<bool> lazyflag;
  void init(int x) {
    n = x;
    sqrtn = sqrt(n);
    k = (n + sqrtn - 1) / sqrtn;
    dat.assign(sqrtn * k, 0);
    buk.assign(k, 0);
    lazy.assign(k, 0);
    lazyflag.assign(k, false);
  }
  void eval(int b) {
    if (!lazyflag[b]) return;
    lazyflag[b] = false;
    for (int i = sqrtn * b; i <= sqrtn * (b + 1) - 1; ++i) {
      dat[i] += lazy[b];
    }
    lazy[b] = 0;
  }
  void add(int l, int r, long long x) {
    for (int b = 0; b < k; ++b) {
      int p = sqrtn * b;
      int q = sqrtn * (b + 1);
      if (q <= l || r <= p) continue;
      if (l <= p && q <= r) {
        buk[b] += x;
        lazyflag[b] = true;
        lazy[b] += x;
      } else {
        eval(b);
        for (int i = max(l, p); i <= min(r, q) - 1; ++i) {
          dat[i] += x;
        }
        buk[b] = INF;
        for (int i = p; i <= q - 1; ++i) {
          buk[b] = min(buk[b], dat[i]);
        }
      }
    }
  }
  long long query(int l, int r) {
    long long ret = INF;
    for (int b = 0; b < k; ++b) {
      int p = sqrtn * b;
      int q = sqrtn * (b + 1);
      if (q <= l || r <= p) continue;
      if (l <= p && q <= r) {
        ret = min(ret, buk[b]);
      } else {
        eval(b);
        for (int i = max(l, p); i <= min(r, q) - 1; ++i) {
          ret = min(ret, dat[i]);
        }
      }
    }
    return ret;
  }
};
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > p(n);
  multiset<int> st;
  for (int i = 0; i < n; ++i) {
    p[i].first = in();
    p[i].second = in();
    st.insert(p[i].second);
  }
  sort((p).begin(), (p).end());
  SqrtDecomposition2 sd;
  sd.init(m + 2);
  for (int i = 0; i < m + 2; ++i) {
    sd.add(i, i + 1, m + 1 - i);
  }
  int ans = 0;
  int j = 0;
  for (int i = 0; i < m + 1; ++i) {
    while (j < n && p[j].first <= i) {
      sd.add(0, p[j].second + 1, -1);
      j++;
    }
    int x = sd.query(i + 1, m + 2);
    ans = max(ans, -x - i);
  }
  cout << ans << endl;
  return 0;
}
