n,k = input().split()
n = int(n)
k = min(int(k),10)
s = []
for j in range(k):
    ins = input().split()
    s.append(int(ins[0]))
    s.append(int(ins[1]))
s = list(set(s))
ans = [0]*(n+1)
ans[1]=1
m = 998244353
for j in range(2,n+1):
    for k in s:
        if(k>=j):
            pass
        else:
            ans[j]=(ans[j]%m+ans[j-k]%m)%m
print(ans[-1]%m)