#include <bits/stdc++.h>
using namespace std;
int n, m, mn[2000000], mark[2000000];
int ans = 99999999;
int read() {
  int x = 0, k = 1;
  char c;
  c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') k = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * k;
}
struct node {
  int l, r;
  friend bool operator<(const node& a, const node& b) { return a.r > b.r; }
} P[2000000];
void push_down(int p) {
  if (!mark[p]) return;
  mark[p << 1] += mark[p], mark[p << 1 | 1] + mark[p];
  mn[p << 1] += mark[p], mn[p << 1 | 1] += mark[p];
  mark[p] = 0;
}
void Update(int p, int l, int r, int L, int R, int x) {
  if (L <= l && R >= r) {
    mn[p] += x;
    mark[p] += x;
    return;
  }
  if (L > r || R < l) return;
  int mid = (l + r) >> 1;
  push_down(p);
  Update(p << 1, l, mid, L, R, x);
  Update(p << 1 | 1, mid + 1, r, L, R, x);
  mn[p] = min(mn[p << 1], mn[p << 1 | 1]);
}
void Build(int p, int l, int r) {
  if (l == r) {
    mn[p] = l;
    return;
  }
  int mid = (l + r) >> 1;
  Build(p << 1, l, mid), Build(p << 1 | 1, mid + 1, r);
  mn[p] = min(mn[p << 1], mn[p << 1 | 1]);
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) {
    P[i].l = read(), P[i].r = read();
    if (P[i].l == P[i].r) P[i].r++;
  }
  sort(P + 1, P + 1 + n);
  int now = 1;
  Build(1, 1, m);
  for (int i = m + 1; i >= 1; i--) {
    while (now <= n && P[now].r >= i) Update(1, 1, m, P[now].l, m, -1), now++;
    Update(1, 1, m, i, i, -1);
    ans = min(ans, (m - i + 1) + mn[1]);
  }
  if (ans < 0)
    printf("%d\n", -ans);
  else
    printf("0\n");
  return 0;
}
