N,K=map(int,input().split())
L=[]
for i in range(K):
    l,r=map(int,input().split())
    L.append([l,r+1])
L.sort()
mod=998244353
A=[0 for i in range(N+1)]
A[1]=1
for i in range(N+1):
    if A[i]>0:
        A[i]%=mod
        for l,r in L:
            for n in range(l+i,r+i):
                if n<=N:
                    A[n]+=A[i]
                else:
                    break
print(A[N]%mod)