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

mod = 998244353

dp = [0]*(N+1)
dp[1] = 1

for i in range(1, N):
    for l, r in LR:
        for x in range(l, r+1):
            y = i+x
            if y > N:
                break
            dp[y] += dp[i]
            dp[y] %= mod

print(dp[N])