N, K = map(int, input().split())
D = []
MOD = 998244353

for i in range(K):
    l, r = map(int, input().split())
    D += list(range(l, r+1))

dp = {}
dp[1] = 1

for i in range(2, N+1):
    dpi = 0
    for d in D:
        if i - d < 1:
            continue
        dpi += dp[i-d]
    dp[i] = dpi % MOD

print(dp[N])
