n, k = map(int, input().split())
step = []
for i in range(k):
    l, r = map(int, input().split())
    for j in range(l, r + 1):
        step.append(j)
step.sort()
lg = len(step)
dp = [0 for _ in range(n + 1)]
dp[1] = 1
for i in range(n + 1):
    for j in step:
        if j < i:
            dp[i] += dp[i - j] 
        else:
            break

print(dp[n]% 998244353)
