n, k = map(int, input().split())
l, r = [0] * k, [0] * k
mod = 998244353
data = []
for i in range(k):
    l, r = map(int, input().split())
    data.append(l)
    data.append(r)

data = list(set(data))
ans = 0
def check(i):
    global ans
    if i >= n:
        if i == n:
            ans += 1
        return 
    for j in range(len(data)):
        check(i + data[j])

check(1)
print(ans % mod)