let inp = readLine()!.split(separator: " ").map { Int($0)! }
let n = inp[0]
let k = inp[1]
var steps: [Int] = .init(repeating: 0, count: n + 1)

var s = Set<Int>()

for _ in 0..<k {
  let range = readLine()!.split(separator: " ").map { Int($0)! }
  let l = range[0]
  let r = range[1]
  
  for i in l...r {
   	s.insert(i)
  }
}

var S = Array(s).sorted()

steps[1] = 1

let mod = 998244353

for i in 1..<n {
  if steps[i] == 0 {
    continue
  }
  for j in S {
  	let next = i + j
    if next > n {
      break
    }
    steps[next] += steps[i]
    steps[next] %= mod
  }
}
print(steps[n])