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

data = list(set(data))
def check():
    global ans
    for i in range(n):
        for j in range(len(data)):
            if i - data[j] < 0:
                continue
            ans[i] = (ans[i] + ans[i - data[j]]) % mod

check()
print(ans[-1] % mod)