n,k=map(int,input().split())
l=[0,1]
a=[1]
kl=[]
mod=998244353
for i in range(k):
    kl.append(list(map(int,input().split())))
for i in range(1,n):
    ans=0
    for li,re in kl:
        ans-=l[max(i-re,0)]
        ans+=l[max(i-li+1,0)]
        ans%=mod
    a.append(ans)
    l.append((l[-1]+ans)%mod)

#print(*a)
#print(*l)
print(a[-1])