N, K = map(int, input().split())
LR = set()
MOD = 998244353

for i in range(K):
    l, r = map(int, input().split())
    for j in range(l, r + 1):
        LR.add(j)
#print(list(LR))

# LR = [list(map(int,input().split())) for i in range(N)]
dp = [0] * (N + 1)
dp[0] = 1
for i in range(1, N):
    for d in LR:
        if i - d < 0: break
        dp[i] += (dp[i - d]) % MOD
print(dp[N-1] % MOD)
