(n,k),*e=[[*map(int,i.split())]for i in open(0)]
mod=998244353
a=[0]*n
a[0]=1
b=[]
e.sort()
for i,j in e:
    b+=range(i,j+1)
for i in range(n):
    for j in b:
        if i+j<n:
            a[i+j]+=a[i]
            a[i+j]%=mod
        else:break
print(a[-1]%mod)