def cc127
    n,m = gets.chomp.split(/\s/).map{|x| x.to_i}

    l = 0
    r = 0
    for i in 1..m
        nl,nr = gets.chomp.split(/\s/).map{|x| x.to_i}
        if i == 1
            l = nl
            r = nr
        else
            l = [[l, nl].max, r].min
            r = [[r, nr].min, l].max
        end
    end

    if r-l < 0
        puts 0
        exit
    end
    puts r-l+1
end

cc127