mod = 998244353
n,k = map(int,input().split())

t = [False] * 20

for i in range(k):
    l,r = map(int,input().split())
    for j in range(l,r+1,1):
        t[j] = True

s = []
for i,v in enumerate(t):
    if v == True:
        s.append(i)

dp = [0] * (n+5)
dp[1] = 1

for i in range(2,n+1,1):
    for d in s:
        if i-d>=1:
            dp[i] += dp[i-d]
            dp[n] %= mod

print(dp[n] % mod)