n,k = map(int,input().split())
mod = 998244353

s = []
for i in range(k):
    l,r = map(int,input().split())
    if l == r:
        s.append(l)
    else:
        s.append(l)
        s.append(r)
s.sort()
# print(s)
dp = [0 for i in range(n+1)]
dp[1] = 1
for i in range(2,n+1):
    for j in s:
        if i-j >= 1:
            dp[i] += dp[i-j]
    # print(dp)
print(dp[n] % mod)