N, K = map(int, input().split())
mod = 998244353
S = []
for i in range(K):
    l, r = map(int, input().split())
    for j in range(l, r+1):
        S.append(j)

S = sorted(S)
dp = [0] * (N+1)
dp[1] = 1
for i in range(1, N):
    for j in S:
        if i + j > N:
            break
        dp[i+j] = (dp[i+j] + dp[i]) % mod

print(dp[N])