n, m = gets.chomp.split.map(&:to_i)
left, right = gets.chomp.split.map(&:to_i)
(m-1).times{
    x, y = gets.chomp.split.map(&:to_i)
    l1, l2 = [left, x].minmax
    r1, r2 = [right, y].minmax
    left, right = l2, r1
    break if left > right
}
puts [right - left + 1, 0].max