MOD = 998244353
N, K = [int(x) for x in input().split()]
S = set()
for _ in range(K):
    L, R = [int(x) for x in input().split()]
    for i in range(L, R+1):
        S.add(i)
dp = [0] * (N+1)
dp[0] = 1
for i in range(N):
    for s in S:
        if i + s >= N: break
        dp[i+s] += dp[i]
print(dp[N-1] % MOD)
