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

S=[]

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

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

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

print(G[n-1])