mod = 998244353

N, K, *LR = map(int, open(0).read().split())

S = set()
for l, r in zip(*[iter(LR)] * 2):
    for i in range(l, r + 1):
        S.add(i)

S = sorted(S)

dp = [0] * N
dp[0] = 1
for i in range(N):
    for s in S:
        if i + s >= N:
            break
        dp[i + s] += dp[i]
        dp[i + s] %= mod

print(dp[-1])