
N, K = map(int, input().split())

kukan = ([0] * (N + 1))
# make table of number
for i in range(K):
    left, right = map(int, input().split())
    kukan[left:right + 1] = [1] * (right - left + 1)
key = []
for i in range(len(kukan)):
    if kukan[i] == 1:
        key.append(i)
# not using kukan after here
dp = [0] * N
dp[0] = 1
# max N*N
for i in range(N):
    for num in key:
        if (i + num) <= N - 1:
            dp[i + num] += dp[i]
        else:
            break
print(dp[N - 1] % (998244353))
