N,K=map(int,input().split())
A=[0]*K
B=[0]*K
p=998244353
for i in range(K):
  A[i],B[i]=map(int,input().split())

dp=[0]*N
dp[0]=1
for i in range(1,N):
  for j in range(K):
    if i>=B[j]:
      dp[i]+=sum(dp[i-B[j]:i-A[j]+1])%p
    elif i>=A[j]:
      dp[i]+=sum(dp[:i-A[j]+1])%p
print(dp[-1]%p)