p = 998244353

N, K = map(int, input().split())

hop = []

for i in range(K):
    L, R = map(int, input().split())
    for j in range(L, R + 1):
        hop.append(j)

dp = [0]*N

dp[0] = 1

for i in range(N - 1):
    for j in range(len(hop)):
        if i + hop[j] < N:
            dp[i + hop[j]] += dp[i]
            dp[i + hop[j]] %= p

print(dp[N - 1] % p)