#include <bits/stdc++.h>
using namespace std;
int del[200005], n, m, ans;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    del[x + 1]++;
    del[y]--;
    if (x == 0 && y == m + 1) ans++;
  }
  n -= ans;
  if (n > m) ans += n - m;
  if (m > n) n = m - ans;
  for (int i = 1; i <= m + 1; i++) del[i] += del[i - 1];
  for (int i = 1; i <= m; i++)
    if (del[i] == n) ans++;
  printf("%d\n", ans);
  return 0;
}
