mod = 998244353
n, k, *LR = map(int, open(0).read().split())
S = set()
for l, r in zip(LR[::2], LR[1::2]):
    for i in range(l, r+1):
        S.add(i)
dp = [0] * (n+1)
dp[1] = 1
for i in range(2, n+1):
    for s in S:
        if i-s >= 0:
            dp[i] += dp[i-s]
            dp[i] %= mod
print(dp[n])