MOD = 998244353

N, K = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(K)]

S = set()
for l, r in lr:
    for j in range(l, r+1):
        S.add(j)

dp = [0] * (N+1)
dp[1] = 1
for i in range(1, N+1):
    for s in S:
        if i+s <= N:
            dp[i+s] += dp[i]
            dp[i+s] %= MOD

print(dp[-1])
