import sys
si = sys.stdin.readline

mod = 998244353
n, k = [int(e) for e in si().split()]
dp, coins = [0 for _ in range(200000+10)], set()
while k:
    k -= 1
    a, b = [int(e) for e in si().split()]
    for i in range(a, b+1):
        coins.add(i)
        dp[1+i] = 1

coins = list(coins)
coins = sorted(coins)
for i in range(1, n+1):
    for coin in coins:
        if i >= coin:
            dp[i] = (dp[i]+dp[i-coin]) % mod
print(dp[n])
