n,k = map(int,input().split())
l_r_list=[list(map(int,input().split())) for _ in range(k)]

import itertools
l_r_list_1 = list(itertools.chain.from_iterable(l_r_list))

l_r_set=set(l_r_list_1)

mv_list=list(l_r_set)

dp = [0]*(n)

for i in range(n):
    for j in range(len(mv_list)):
        if i > mv_list[j]:
            dp[i] += dp[i - mv_list[j]]
        elif i == mv_list[j]:
            dp[i] += 1

print(dp[-1] % 998244353)