n, k = map(int, input().split())
s = set()
for i in range(k):
    l = list(map(int, input().split()))
    s = set(l+list(s))
dp=[0]*(n+1)
dp[1] = 1
p = 998244353

for i in range(1, n):
    for j in s:
        if i+j > n:
            continue
        dp[i+j] += (dp[i])
        dp[i+j] %= p

print(dp[n])