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)

dic = dict()
dic[1] = 1

for i in range(1,n+1):
    if i in dic.keys():
        for j in s:
            if i + j in dic.keys():
                dic[i+j] += dic[i]
            else:
                dic[i+j] = dic[i]

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

