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

mod = 998244353
dp = [0] * (2*n)
dp[1] = 1
for i in range(n):
    for j in s:
        dp[i+j] += dp[i]
        dp[i+j] %= mod
print(dp[n])
