n, k = map(int, input().split())
s = []
mod = 998244353
for _ in range(k):
    l, r = map(int, input().split())
    s += [i for i in range(l, r + 1)]

s.sort()

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

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

print(dp[n] % mod)
