n,k = list(map(int,input().split()))
s = set()

for i in range(k):
    l,r = list(map(int,input().split()))
    for i in range(l,r+1):
        s.add(i)
lis = list(s)
lis = sorted(lis)
dic = dict()
dic[1] = 1

for i in range(1,n+1):
    if i in dic.keys():
        #for j in s:
        for j in range(0,len(lis)):#
            #if i + j in dic.keys():
            if i + lis[j] in dic.keys():
                #dic[i+j] += dic[i]
                dic[i+lis[j]] += dic[i]
            else:
                #dic[i+j] = dic[i]
                dic[i+lis[j]] = dic[i]
            if i + lis[j] > n:#
                break#

if n in dic.keys():
    print(dic[n] % 998244353)
else:
    print(0)
