n,k=map(int,input().split(" "))

S=[]

for i in range(k):
  a,b=map(int,input().split(" "))
  for i in range(a,b+1):
    S.append(i)
S=list(set(S))

G=[0 for i in range(n+max(S))]
G[0]=1

for i in range(n-1):
  for j in range(int(len(S))):
    k=i+S[j]
    G[k]=(G[k]+G[i])%998244353

print(G[n-1])