n,k=map(int,input().split())
a=list([1]+[0]*(n-1))
lst=[]
for i in range(k):
    x,y=map(int,input().split())
    lst+=list(range(x,y+1))

from functools import lru_cache
@lru_cache(maxsize = None)
def f()
    for j in lst:
        if j<=i:a[i]+=a[i-j]
for i in range(1,n):f()
print(a[-1]%998244353)