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