N,K=map(int,input().split())
A=[0 for i in range(2*10**5+1)]
A[1]=1
S=[]
for i in range(K):
  L,R=map(int,input().split())
  for i in range(L,R+1):
    S.append(i)
S.sort()
import copy
mod=998244353
for i in range(1,N):
  for j in range(len(S)):
    if i+S[j]<=N:
      A[S[j]+i]+=A[i]
      A[S[j]+i]%=mod
    else:
      S=S[:j]
      break

    
print(A[N])