n,k = map(int,input().split())
mod = 998244353
lr = []
for i in range(k):
  l,r = map(int,input().split())
  lr.append(l)
  lr.append(r)
S = list(set(lr))
n-=1
rout=0
def travel(n,S,rout):
  for s in S:
    if n<s:
      continue
    if n-s>0:
      return travel(n-s,S,rout)
    else:
      rout+=1
travel(n,S,rout)
print(rout%mod)