#include <bits/stdc++.h>
const int maxn = 2e5 + 5;
struct Seg {
  int x, y;
} a[maxn];
int n, m, ans;
inline int cmp(const Seg A, const Seg B) {
  return A.x == B.x ? A.y < B.y : A.x < B.x;
}
int l[maxn << 2], r[maxn << 2], tag[maxn << 2], mx[maxn << 2];
inline int max(int a, int b) { return a > b ? a : b; }
inline void add(int i, int v) { tag[i] += v, mx[i] += v; }
inline void pushup(int i) { mx[i] = max(mx[i << 1], mx[i << 1 | 1]); }
void build(int x, int y, int i) {
  l[i] = x, r[i] = y;
  if (x == y) {
    mx[i] = x;
    return;
  }
  int mid = x + y >> 1;
  build(x, mid, i << 1), build(mid + 1, y, i << 1 | 1);
  pushup(i);
}
inline void pushdown(int i) {
  if (!tag[i]) return;
  add(i << 1, tag[i]), add(i << 1 | 1, tag[i]);
  tag[i] = 0;
}
void change(int x, int y, int v, int i) {
  if (x <= l[i] && y >= r[i]) {
    add(i, v);
    return;
  }
  int mid = l[i] + r[i] >> 1;
  pushdown(i);
  if (x <= mid) change(x, y, v, i << 1);
  if (y > mid) change(x, y, v, i << 1 | 1);
  pushup(i);
}
int query(int x, int y, int i) {
  if (x <= l[i] && y >= r[i]) return mx[i];
  int mid = l[i] + r[i] >> 1;
  pushdown(i);
  if (y <= mid) return query(x, y, i << 1);
  if (x > mid) return query(x, y, i << 1 | 1);
  return max(query(x, y, i << 1), query(x, y, i << 1 | 1));
}
int main() {
  scanf("%d%d", &n, &m);
  for (register int i = 1; i <= n; i++) scanf("%d%d", &a[i].x, &a[i].y);
  std::sort(a + 1, a + n + 1, cmp);
  int nl = 0, nr = m + 1;
  for (register int i = 1; i <= n; i++)
    nl = max(nl, a[i].x), nr = ((nr) < (a[i].y) ? (nr) : (a[i].y));
  ans = n + (nl < nr ? nr - nl - 1 : 0);
  build(0, m + 1, 1);
  for (register int i = 1; i <= n; i++) {
    int nw = query(a[i].x + 1, a[i].y, 1);
    ans = max(ans, nw - a[i].x);
    change(0, a[i].y, 1, 1);
  }
  printf("%d\n", ans - m);
  return 0;
}
