N, K = map(int, input().split())

LR = [map(int, input().split()) for _ in range(K)]
MOD = 998244353
dic = set()
for l, r in LR:
    for i in range(l, r+1):
        dic.add(i)
dic = list(dic)
dp = [0]*(N+1)
dp[1] = 1

for i in range(2, N+1):
    tmp = i-1
    t = [x for x in dic if x <= tmp]
    for s in t:
        dp[i] += dp[i-s]
        dp[i] %= MOD
print(dp[-1])
