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

def main():
    N, K = i_map()
    S = set()
    dp = [0] * (N + 1)
    for _ in range(K):
        L, R = i_map()
        S = S | set(range(L, R + 1))
    dp[1] = 1
    for n in range(1, N + 1):
        if dp[n] == 0:
            continue
        for s in S:
            if n + s <= N:
                dp[n + s] += dp[n]
    print(dp[N] % MOD)

if __name__ == "__main__":
    main()
