import collections

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

c = 0
q = collections.deque()
for i in range(k):
    l,r = map(int,input().split())
    for j in range(l,r+1):
        c += 1
        q.append(j)
print(q)

dp = [0 for i in range(n+1)] 
dp[1] = 1

i = 0
while q:
    i += 1
    tmp = q.pop()
    for j in range(1,n+1):
        if j+tmp <= n:
            dp[j+tmp] = (dp[j] + 1)%mod

print(dp[n]%mod)