n,k = list(map(int, input().split()))
s = set()
for _ in range(k):
    l,r = list(map(int, input().split()))
    for i in range(l,r+1):
        s.add(i)

dp = [0] * n
dp[0] = 1

for i in range(n-1):
    for j in s:
        if i+j < n:
            dp[i+j] += dp[i]
            dp[i+j] %= 998244353

print(dp[-1])