

def findtheways(N,K,S):
  # s is o add kr sorted
  dp=[0]*(N+1)
  dp[1]=1
  for i in range(2,N+1):
    for everyItem in S:
      if (i-everyItem)>0:
        dp[i]+=dp[i-everyItem]
  return dp[N]%998244353
N, K=map(int,input().split())
final_list=[]
while K>0:
  a=list(map(int,input().split()))
  final_list+=a
  K-=1

final_list=sorted(list(set(final_list)))

print(findtheways(N,K,final_list))
