#include <bits/stdc++.h>
using namespace std;
long long n, m, i, a[202020], hz, ta, tb;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> ta >> tb;
    a[1]++;
    a[ta + 1]--;
    a[tb]++;
  }
  for (i = 1; i <= m; i++) {
    hz += a[i];
    if (hz > 0) n--;
  }
  n = max(n, 0LL);
  cout << n << "\n";
}
