n, k = list(map(int, input().split()))
s = []
for i in range(k):
    a, b = list(map(int, input().split()))
    for j in range(a, b+1):
        s.append(j)
s = set(s)
dp = [0]*(n+1)
dp[1] = 1
mod = 998244353
for i in range(1, n+1):
    for ss in s:
        if i+ss <= n:
            dp[i+ss] += dp[i]
            dp[i+ss] %= mod
print(dp[-1])
