n, k = map(int, input().split())
ls = []
rs = []
ps = []
MOD = 998244353
s = set()
for _ in range(k):
    l,r = map(int, input().split())
    for i in range(l,r+1):
        s.add(i)
dp = [0] * (n+1)
dp[0] = 1
imos = [0]
for i in range(n):
    for d in sorted(list(s), reverse=True):
        if i - d >= 0:
            dp[i] += dp[i-d]
            dp[i-1] -= dp[i]
            dp[i] %= MOD

print(dp[n-1])