MOD = 998244353
N, K = list(map(int, input().split()))

dp = [0] * (N+1)

mvlst = list()
for i in range(K):
    l, r = list(map(int, input().split()))
    for j in range(l, r+1):
        mvlst.append(j)

dp[1] = 1
for i in range(1, N+1):
    for j in range(len(mvlst)):
        if i-mvlst[j]<1: continue
        dp[i] += dp[i-mvlst[j]]
        dp[i] = dp[i] % MOD

print(dp[N] % MOD)
