def solve(n, m, l, r)
  _l = l.max
  _r = r.min
  if _r <= _l
    chair_num = m
  else
    chair_num = _l + m - _r + 1
  end
  [0, n - chair_num].max
end

n, m = gets.split.map(&:to_i)
l, r = n.times.map { gets.split.map(&:to_i) }.transpose
p solve(n, m, l, r)

