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

dp = [0] * N
dp[0] = 1
for i in range(1, N):
    for j in range(1, i + 1):
        if S[j]:
            dp[i] += dp[i - j]
print(dp[-1] % MOD)
