n,k=map(int,input().split())
l=[list(map(int,input().split())) for i in range(k)]
x=[0]*(n+1)
x[0]=1
l.sort()
t=0
for i in range(1,n+1):
    for j in range(k):
        if i-l[j][1]>0:
            t+=x[i-l[j][0]]-x[i-l[j][1]-1]
        elif i-l[j][0]>=0:
            t+=x[i-l[j][0]]
        t=t%998244353
        x[i]=t
print(x[n-1])