#include <bits/stdc++.h>
using namespace std;
using LL = long long;
template <class T, size_t D>
struct vec : vector<vec<T, D - 1>> {
  template <class... Args>
  vec(size_t n = 0, Args... args)
      : vector<vec<T, D - 1>>(n, vec<T, D - 1>(args...)) {}
};
template <class T>
struct vec<T, 1> : vector<T> {
  template <class... Args>
  vec(Args... args) : vector<T>(args...) {}
};
template <class T>
inline bool asMn(T& a, const T& b) {
  return a > b ? a = b, true : false;
}
template <class T>
inline bool asMx(T& a, const T& b) {
  return a < b ? a = b, true : false;
}
inline int nex(int i, int n) { return i == n - 1 ? 0 : i + 1; }
inline int pre(int i, int n) { return !i ? n - 1 : i - 1; }
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vec<pair<int, int>, 1> a(n);
  for (auto& i : a) {
    cin >> i.first >> i.second;
  }
  int ans = 0;
  for (int mask = 0; mask < 1 << n; ++mask) {
    int l = 0, r = m + 1;
    for (int i = 0; i < n; ++i) {
      if (mask >> i & 1) {
        asMx(l, a[i].first);
        asMn(r, a[i].second);
      }
    }
    if (l < r) {
      asMx(ans, __builtin_popcount(mask) - l - (m - r + 1));
    } else {
      asMx(ans, __builtin_popcount(mask) - m);
    }
  }
  cout << ans << '\n';
  return 0;
}
