N, K = map(int, input().split())
mod = 998244353
D = []
dp = [0] * (N+10)
for i in range(K):
    L, R = map(int, input().split())
    for i in range(L, R+1):
        D.append(i)

D = sorted(D)
dp[0] = 1
for i in range(N):
    for d in D:
        if i + d > N:
            continue
        dp[i + d] += dp[i]
        dp[i + d] %= mod

print(dp[N-1])

