from itertools import accumulate
n, k = map(int, input().split())
l = [0]*(n+10)
imos = [0]*(n+10)
mod = 998244353

for i in range(k):
    a, b = map(int, input().split())
    l[a] += 1
    l[b+1] -= 1
imos = list(accumulate(l))

s = []
for i in range(len(imos)):
    if i <= n and imos[i] == 1:
        s.append(i)
s.sort()
dp = [0]*(n+2)
dp[1] = 1

for i in range(1,n+1):
    for ss in s:
        if i+ss>n:continue
        if imos[i] == 1:
            dp[i+ss] += dp[i]
            imos[i+ss] = 1
            dp[i+ss] %= mod

print(dp[n]%mod)

