# TLE: 通常の DP (もらう DP)
# dp[i] = dp[i-x]
n, k = map(int, input().split())

S = []
for _ in range(k):
    l, r = map(int, input().split())
    for s in range(l, r+1):
        S.append(s)

MOD = 998244353
dp = [0]*(n+1)  # [0,n]
dp[1] = 1

for i in range(1, n+1): # i:[1,n]
    for s in S: # max n個ある！
        if i-s >= 0:
            dp[i] += dp[i-s]
            dp[i] %= MOD

print((dp[n] + MOD) % MOD)
