N,K=map(int, input().split())
mod=998244353
D=[0]*(2*N+2)
D[0]=1
A=[]
for i in range(K):
  L,R=map(int, input().split())
  A.append((L,R))
A=sorted(A)
#print(A)
for i in range(N-1):
  for a,b in A:
    if i+a<=N:
      for j in range(i+a,min(i+b+1,N)):
        D[j]+=D[i]
        D[j]%=mod
print(D[N-1])