N, K = list(map(int, input().split()))
C = 998244353
S = set()
for _ in range(K):
    l, r = list(map(int, input().split()))
    S |= set(range(l, r+1))
# print(S)

dp = [0]*N
dp[0] = 1
for i in range(N-1):
    if dp[i] == 0:
        continue
    for j in S:
        if i+j < N:
            dp[i+j] = (dp[i+j]+dp[i]) % C
# print(dp)
print(dp[-1] % C)
