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

s = []
for i in range(k):
    ss,se = map(int, input().split())
    slist = list(range(ss,se+1))
    s.append(slist)

import itertools
s = list(itertools.chain.from_iterable(s))

s.sort()

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

for l in range(1,n):
    for m in s:
        if l-m <0:
            break
        dp[l] = (dp[l] +dp[l-m]) % 998244353 

print(dp[n-1]%998244353 )