from sys import stdin
input = stdin.readline

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

ls = []
mod = 998244353

for _ in range(K):
    l, r = map(int, input().split())
    for i in range(l, r + 1):
        ls.append(i)

dp = [0] * (N + 1)
dp[1] = 1

ls.sort()

for j in range(1, N):
    for x in ls:
        if x + j > N:
            break
        else:
            dp[x + j] += dp[j]

print(dp[N] % mod)
# print(dp)
