N, K = map(int, input().split())
S = []
for _ in range(K):
    L, R = map(int, input().split())
    S.extend([i for i in range(L, R+1)])

S.sort()

dp = [0]*N
dp[0] = 1

for i in range(N):
    dpi = dp[i]
    if dpi == 0:
        continue
    for value in S:
        if i + value >= N:
            break
        dp[i+value]+=dpi

print(dp[-1]%998244353)
