mod=998244353
n,k=map(int,input().split())
s=set()
for i in range (k):
    x,y=map(int,input().split())
    s.update([x,y])

dp=[0 for i in range (n+1)]
dp[1]=1


for i in range (2,n+1):
    x=0
    for val in s:
        if (i-val)<0:
            continue
        x+=dp[i-val]
    if x<mod:
        dp[i]=x
    else:
        dp[i]=x%mod

print (dp[n])
