N,K=map(int,input().split())
LR=set()
inf_=998244353
dp=[0]*(N+100)
dp[1]=1

for i in range(K):
    lr=list(map(int,input().split()))
    LR = LR |set(lr)
li=list(LR)
for i in range(2,N+1):
    for j in li:
        try:
            dp[i]+=dp[i-j]
        except IndexError:
            pass
print(dp[N]%inf_)    