N, K = map(int, input().split())
S = set()
for _ in range(K):
    l, r = map(int, input().split())
    S = S | set(range(l, r + 1))
mod = 998244353

dp = [0 for _ in range(3 * N)]
for s in S:
    dp[s + 1] = 1
for i in range(1, N + 1):
    for s in S:
        dp[i] += dp[i - s]
        dp[i] %= mod
print(dp[N] % mod)