Devisor = 998244353
N, K = gets.chomp.split(' ').map(&:to_i)
sectinos = Array.new(K){ gets.chomp.split(' ').map(&:to_i) }

union = []
sectinos.each do |section|
    s, e = section
    s.upto(e) { |i| union.push(i) }
end

# lcm = union.inject(:lcm)

rest = N - 1
min = union.min
max = union.max

# ans = 0
# 1.upto(rest / min) do |k|
#     union.repeated_permutation(k) do |perm|
#         ans += 1 if perm.sum == rest
#     end
# end
# puts ans % Devisor

mas = Array.new(N + 1){ 0 }
union.each do |u|
    mas[-1 - u] += 1 if -1 - u >= N * -1
end
# p mas

(-1 - min).downto(N * -1 + min) do |i|
    next if mas[i] == 0
    union.each do |u|
        # puts "i = #{i}, u = #{u}"
        pos = i - u
        mas[pos] += mas[i] if pos >= N * -1
        # p mas
    end
end
puts mas[1] % Devisor