n,k = map(int,input().split())
d = list(list(map(int,input().split())) for _ in range(k))
mod = 998244353
d = list(set(sum(d,[])))

def leap(N,D):
    dp = [0]*N # dp[i]はiへ行く場合の数 
    dp[0]=1
    for i in range(N):
        for j in D:
            if i-j >=0:
                dp[i] += dp[i-j]
    return dp
print(leap(n,d)[-1]%mod)