from sys import stdin
readline = stdin.readline
def i_input(): return int(readline().rstrip())
def i_map(): return map(int, readline().rstrip().split())
def i_list(): return list(i_map())

MOD = 998244353

import numpy as np
from numba import jit

@jit
def main():
    N, K = i_map()
    S = set()
    dp = np.zeros(N + 1, dtype=int)
    for _ in range(K):
        L, R = i_map()
        S = S | set(range(L, R + 1))
    S = list(S)
    S.sort()
    dp[1] = 1
    for n in range(2, N + 1):
        for s in S:
            if n - s >= 1:
                dp[n] += dp[n - s] % MOD
            else:
                break
    print(dp[N] % MOD)

if __name__ == "__main__":
    main()
