#!/usr/bin/env ruby

N, K = gets.chomp.split.map(&:to_i)

LR = []

K.times do |i|
  LR[i] = gets.chomp.split.map(&:to_i)
end

LR.sort_by!(&:first)

dp = [0, 1]

2.upto(N) do |i|
  enum = Enumerator.new {|y|
    LR.each do |(l, r)|
      l.upto(r) { |v| y << v }
    end
  }

  dp[i] = 0
  enum.each do |v|
    break if v > i

    dp[i] += dp[i - v]
  end
end

puts dp[N] % 998244353

