let m = 998244353

let n, k = Scanf.scanf "%d %d" (fun n k -> n, k)
let lr = Array.init (k * 2) (fun _ -> Scanf.scanf " %d" (fun i -> i))

let sum = Array.make (n + 2) 0

let rec f i =
  if i = n + 1 then sum.(n + 1) - sum.(n)
  else
    let rec g j dp =
      if j = 2 * k then dp
      else
        let r = i - lr.(j) in
        let l = max 1 (i - lr.(j + 1)) in
        if r < 1 then g (j + 2) dp
        else g (j + 2) ((dp + sum.(r + 1) - sum.(l)) mod m) in
    sum.(i + 1) <- (sum.(i) + g 0 0) mod m;
    f (i + 1)

let () =
  sum.(2) <- 1;
  Printf.printf "%d\n" (f 2)
