N, K = map(int, input().split())
L = [list(map(int, input().split())) for i in range(K)]

S = []

for i in range(K):
    for j in range(L[i][0], L[i][1] + 1):
        S.append(j)

S.sort()

dp = [0] * N

for x in range(N):
    for y in S:
        if x > y:
            dp[x] = (dp[x] + dp[x - y]) % 998244353

    if x in S:
        dp[x] += 1

print(dp[N - 1])
