from itertools import chain
(N,K), *lr = [list(map(int, s.split())) for s in open(0)]
lr.sort()
mstep = lr[0][0]
MOD = 998244353
dp = [0] * (N+1)
dp[1] = 1

steps = list(chain.from_iterable(range(l, r+1) for l, r in lr))

for i in range(2, N+1):
    dp[i] = sum(dp[i-step] for step in steps if i-step >= 1) % MOD
print(dp[-1])