N,K=map(int,input().split())
A=[0 for i in range(2*10**5+1)]
A[1]=1
S=set()
for i in range(K):
  L,R=map(int,input().split())
  for i in range(L,R+1):
    S.add(i)
import copy
mod=998244353
for i in range(1,N):
  temp=S.copy()
  for j in S:
    if j+i>N:
      temp.remove(j)
    else:
      A[j+i]+=A[i]
      A[j+i]%=mod
  S=temp
    
    
print(A[N])