n,k=map(int,input().split())
mod=998244353
dp=[0]*2*n
dp[n]=1
l=[list(map(int,input().split(" "))) for i in range(k)]
for i in range(n,2*n):
    for j in range(k):
        for m in range(l[j][0],l[j][1]+1):
          dp[i]+=dp[i-m]%mod
print(dp[2*n-1]%mod)
