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

dp = [0] * (N+1)
mv = list()
for i in range(K):
    l, r = list(map(int, input().split()))
    for j in range(l, r+1):
        mv.append(j)

def solve(N, dp, mv):
    for i in range(1, N+1):
        for j in range(len(mv)):
            if i+mv[j]>N: break
            if dp[i] == 0: continue
            dp[i+mv[j]] = (dp[i+mv[j]] + dp[i]) % MOD

dp[1] = 1
mv.sort()
solve(N, dp, mv)

print(dp[N])
