N,K = map(int,input().split())
LR = [list(map(int,input().split())) for _ in range(K)]
MOD = 998244353

S = []
for l,r in LR:
    for _ in range(l,r+1):
        S.append(_)
S = list(set(S))
S.sort()

dp = [0] * (N+1)
dp[1] = 1
tmp = 0
for i in range(2,N+1):
    for s in S:
        if i - s >= 1:
            tmp += dp[i-s]
            dp[i] += tmp
            tmp = 0
        else:
            break
    dp[i] %= MOD
print(dp[-1])