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

d=[]

for i in range(k):
  l,r=map(int,input().split())
  if l not in d:
    d.append(l)
  if r not in d:
    d.append(r)
#print(d)
m=[0]*n
m[0]=1

for i in range(n):
  for j in range(len(d)):
    if (i+d[j])<n:
      m[i+d[j]]+=m[i]

#print(m)
print(m[n-1]%998244353)