p=998244353

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

LR=[]
for i in range(k):
    Li,Ri=map(int,input().split())
    LR.append([Li,Ri])

U=[0,1]

cnt=[1]
for i in range(1,n):#i:=position
    cnti=0
    for Li,Ri in LR:
        scopeL=i-Ri
        scopeR=i-Li
        if scopeR>=0:
            cnti+=U[scopeR+1]-U[max(0,scopeL)]#sum[max(0,scopeL),scopeR+1]
    cnt.append(cnti%p)
    U.append((U[i]+cnti)%p)

print(cnt[n-1])