n, k = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(k)]
MOD = 998244353
cand = []
for l, r in lr:
    for i in range(l, r+1):
        cand.append(i)
cand.sort()
# print(cand)
dp = [0] * (n+1)
dp[0] = 1
for i in range(1, n+1):
    tmp = 0
    for num in cand:
        if i - num >= 0:
            tmp += dp[i-num]
            tmp %= MOD
        else:
            dp[i] = (tmp % MOD)
            break
    dp[i] = (tmp % MOD)
print(dp[-2])