n , k = map(int, input().split())

li = [0]*(n+2)
lis=[]
lis2 =[0]*(3*n)
lis2[1]=1

for i in range(k):
    l,r = map(int, input().split())
    li[l]=1
    li[r+1]=-1

for i in range(1,n+1):
    li[i]+=li[i-1]

for i in range(1,n+1):
    if li[i]==1:
        lis.append(i)

for i in range(1,n):
    for j in lis:
        lis2[i]%=998244353
        lis2[i+j]+=lis2[i]

print(lis2[n]%998244353)
