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

mod = 998244353
dp = [0] * (n+1)
dp[1] = 1
s = sorted(s)
for i in range(1, n):
    dp[i] %= mod
    for add in s:
        if i+add <= n:
            dp[i+add] += dp[i]
print(dp[n] % mod)