n,k = list(map(int.list(input().split())))
s = []
for i in range(k):
  s.append(list(map(int.list(input().split()))))
  
l = []
for i in s:
  l.extend(i)
l = list(set(l))  
dp=[0]*(n+1)
for i in l:
    dp[i]=1
for i in range(n+1):
    for j in l:
        if i-j>0:
            dp[i]+=dp[i-j]
    #print(dp)        
print(dp[-2]%998244353)