N, K = map(int, input().split())
S = []
for _ in range(K):
    l, r = map(int, input().split())
    S += [i for i in range(l, r+1)]
S.sort()
mod = 998244353

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