import sys
sys.setrecursionlimit(1000000000)
N,K=map(int,input().split())
rangs=[]
for _ in range(K):
    l,r=map(int,input().split())
    for i in range(l,r+1):
        rangs.append(i)
from functools import lru_cache
@lru_cache(maxsize=None)
def dynam(n):
    res=0
    for go in rangs:
        if n==go:
            res+=1
        elif n>go:
            res+=dynam(n-go)
    return res
print(dynam(N-1)%998244353)