module LazySegmentTree : sig
    type t

    val create: int array -> t
    val add : t -> int -> int -> int -> unit
    val getsum : t -> int -> int -> int
end = struct
    type t = int * int array * int array

    let z = 998244353

    let ( +@) a b = (a + b) mod z
    let ( *@) a b = (a * b) mod z

    let div2 a = if a mod 2 = 0 then a / 2 else (a + z) / 2

    let create arr =
        let sz = Array.length arr in
        let rec loop n =
            if n < sz then loop (n * 2) else n
        in
        let n = loop 1 in
        let node = Array.make (2 * n - 1) 0 in
        let laze = Array.make (2 * n - 1) 0 in
        for i = 0 to sz - 1 do node.(i + n - 1) <- arr.(i); done;
        for i = n - 2 downto 0 do node.(i) <- node.(i * 2 + 1) +@ node.(i * 2 + 2); done;
        n, node, laze

    let eval (n, node, laze) k l r =
        if laze.(k) <> 0 then (
            node.(k) <- node.(k) +@ laze.(k);
            if (r - l > 1) then (
                laze.(2 * k + 1) <- laze.(2 * k + 1) +@ div2 laze.(k);
                laze.(2 * k + 2) <- laze.(2 * k + 2) +@ div2 laze.(k);
            );
            laze.(k) <- 0
        )

    let rec add2 ((n, node, laze) as tree) a b x k l r =
        let r = if r < 0 then n else r in
        eval tree k l r;

        if b <= l || r <= a then () else (
            if a <= l && r <= b then (
                laze.(k) <- laze.(k) +@ (r - l) *@ x;
                eval tree k l r
            ) else (
                add2 tree a b x (2 * k + 1) l ((l + r) / 2);
                add2 tree a b x (2 * k + 2) ((l + r) / 2) r;
                node.(k) <- node.(2 * k + 1) +@ node.(2 * k + 2)
            )
        )
    let rec getsum2 ((n, node, laze) as tree) a b k l r =
        let r = if r < 0 then n else r in
        if b <= l || r <= a then 0 else (
            eval tree k l r;
            if a <= l && r <= b then node.(k) else
                let vl = getsum2 tree a b (2 * k + 1) l ((l + r) / 2) in
                let vr = getsum2 tree a b (2 * k + 2) ((l + r) / 2) r in
                vl +@ vr
        )

    let add tree a b x = add2 tree a b x 0 0 (-1)
    let getsum tree a b = getsum2 tree a b 0 0 (-1)
end ;;
Scanf.scanf "%d %d" (fun n k ->
    let lr = Array.init k (fun _ -> Scanf.scanf " %d %d" (fun l r -> l, r)) in
    let arr = Array.make n 0 in
    arr.(0) <- 1;
    let tr = LazySegmentTree.create arr in
    for i = 0 to n - 1 do
        let g = LazySegmentTree.getsum tr i (i + 1) in
        Array.iter (fun (l, r) ->
            if i + l < n then LazySegmentTree.add tr (i + l) (min (i + r + 1) n) g
        ) lr
    done;
    Printf.printf "%d\n" @@ LazySegmentTree.getsum tr (n - 1) n
)