N, K = map(int, input().split())
S = []
for j in range(K):
    LRj = list(map(int, input().split()))
    for s in range(LRj[0], LRj[1] + 1):
        S.append(s)

m =  998244353

# print(S)

dp = [0] * N
dp[0] = 1
for i in range(1, N):
    for s in S:
        if s <= i:
            # print(i, i-s)
            dp[i] += dp[i - s] % m
            dp[i] %= m

ans = dp[N - 1]

print(ans)