n,k=map(int,input().split())
ans=[0]*(n+1)
ans[1]=1
cnt=[]
for i in range(k):
    l,r=map(int,input().split())
    for j in range(l,r+1):
        cnt.append(j)
cnt.sort()
cnt2=1
cnt3=0
mod=998244353
if len(cnt)==n:
    print(pow(2,n-2,mod))
elif len(cnt)==n-1 and cnt[-1]==n-1:
    print(pow(2,n-2,mod))
else:
    for i in range(1,n):
        for j in range(len(cnt)):
            if i+cnt[j]>n:
                cnt=cnt[:j]
                break
            ans[i+cnt[j]]+=ans[i]
            ans[i+cnt[j]]%=mod
        if j==0:
            break
    print(ans[n])
