N,K=map(int,input().split())
L=list()
R=list()
dp=[0]*N
dp[0]=1
for i in range(K):
    l,r=map(int,input().split())
    L.append(l)
    R.append(r)
for i in range(0,N):
    for k in range(K):
        for j in range(L[k],R[k]+1):
            if i+j>N-1:
                break
            else:
                dp[i+j]+=dp[i]%998244353
print(dp[N-1]%998244353)