N, K = map(int, input().split())
A = [list(map(int,input().split())) for i in range(K)]

S = []
for l, r in A:
    for i in range(l, r + 1):
        S.append(i)

dp = [0]*N
dp[0] = 1

for i in range(1, N):
    c = 0
    for j in S:
        if i - j >= 0:
            c += dp[i-j]
    dp[i] = c

print(dp[N-1]%998244353