N,K=map(int,input().split())
pr=998244353
ku=[list(map(int, input().split())) for i in range(K)]
l=[0]*(N)
l[0]=1
for i in range(1,N):
    t=0
    for j in ku:
        if i>=j[0]:
            if i>j[1]:
                t+=l[i-j[0]]-l[i-j[1]-1]
            else:
                t+=l[i-j[0]]
    l[i]=(l[i-1]+t)%pr
print((l[-1]-l[-2])%pr)
