from sys import setrecursionlimit
setrecursionlimit(10 ** 8)
n, k = [int(i) for i in input().split()]
mod = 998244353
d = []
for i in range(k):
    l, r = [int(i) for i in input().split()]
    d += list(range(l, r+1))
d.sort()

dp = [-1] * n
dp[-1] = 1

def c(x):
    if dp[x] != -1:
        return dp[x]
    cnt = 0
    for i in d:
        if x + i >= n:
            break
        cnt += c(x + i) if dp[x+i] == -1 else dp[x+i]
    dp[x] = cnt % mod
    return dp[x]

print(c(0))

"""
for i in range(1, n+1):
    index = n - i
    for j in d:
        if index + j >= n: break
        dp[index] = (dp[index] + dp[index + j]) % mod

print(dp[0])
"""