import numpy as np

N, K = map(int, input().split())
MOD = 998244353
dp = [0 for _ in range(N)]
dp[0] = 1

L, R = [0 for _ in range(K)], [0 for _ in range(K)]
for k in range(K):
    L[k], R[k] = map(int, input().split())

for i in range(N):
    tmp = dp[i]
    for k in range(K):
        # dp[min(i+L[k], N-1):min(i+R[k]+1, N)] += dp[i]
        for d in range(min(i+L[k], N-1), min(i+R[k]+1, N)):
            dp[d] += tmp
            dp[d] %= MOD

ans = dp[N-1] % MOD
print(ans)
