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

LR = [list(map(int, input().split())) for i in range(K)]
S = set()
for i in LR:
    for j in range(i[0], i[1]+1):
        S.add(j)
L = list(S)

dp = [0 for i in range(N)]
dp[0] = 1
for i in range(1, N):

    t = [j for j in L if j <= i]

    for j in t:
        dp[i] += dp[i-j]

print(dp[-1] % 998244353)
