MOD = 998244353
N, K = gets.split.map &:to_i
LRs = $<.map{|s|
  s.split.map &:to_i
}

set = []
LRs.each{|l, r|
  (l..r).each{|i|
    set << i
  }
}

$memo = Hash.new 0
$memo[0] = 1

(1...N).each{|i|
  set.each{|j|
    $memo[i] += $memo[i - j]
  }
  $memo[i] %= MOD
}
p $memo[N-1]