N,K,*LR=map(int,open(0).read().split())
S=set()
for i in range(0,K*2,2):
    S |= set(range(LR[i],LR[i+1]+1))
cache={1:1}
def count(n):
    if n in cache:
        return cache[n]
    ans=0
    for s in S:
        ns=n-s
        if ns==1:
            ans+=1
        elif ns>1:
            ans+=count(ns)
    cache[n]=ans
    return ans
print(count(N)%998244353)