#include <bits/stdc++.h>
using namespace std;
const int BIT_MAX = 200010;
template <class T>
class BIT {
  T x[BIT_MAX + 1];

 public:
  BIT() { fill(x, x + BIT_MAX + 1, 0); }
  void add(int a, T b) {
    for (; a <= BIT_MAX; a += a & -a) x[a] += b;
  }
  T get(int a) {
    T b = 0;
    for (; a > 0; a -= a & -a) b += x[a];
    return b;
  }
};
const int MC = 200010;
int N, M;
pair<int, int> x[MC];
BIT<int> bit;
int main() {
  scanf("%d%d", &N, &M);
  for (int i = (int)(0); i < (int)(N); ++i) {
    int L, R;
    scanf("%d%d", &L, &R);
    if (L + 1 == R) {
      L = M;
      R = M + 1;
    }
    x[i] = make_pair((L), (R));
    bit.add(L + 1, 1);
    bit.add(R, -1);
  }
  sort(x, x + N);
  int z = 0;
  for (int i = (int)(1); i < (int)(M + 1); ++i) {
    if (bit.get(i) == N) ++z;
  }
  printf("%d\n", max(0, N - M + z));
  return 0;
}
