f=lambda:map(int,input().split())
N,K=f()

S=[tuple(f()) for i in [0]*K]
p=998244353

dp=[0]*(N+1)
dp[1]=1
def To(n):
    for l,r in S:
        for i in range(r-l+1):
            if n+l+i<=N:
                dp[n+l+i]=(dp[n+l+i]+dp[n])%p
            else:
                break
                
for n in range(1,N+1):
    To(n)
print(dp[N]%p)