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

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

for i in range(1, n):
    for ss in s:
        if i-ss >= 0:
            dp[i] += dp[i-ss]
            dp[i] %= mod

print(dp[-1]%mod)