import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K, *LR = map(int, read().split())

MOD = 998244353
a = []
dp = [0] * (N+1)

dp[0] = 0
dp[1] = 1

for L, R in zip(LR, LR):
    if L in a:
        continue
    else:
        a.append(L)
    if R in a:
        continue
    else:
        a.append(R)

print(a)

for i in range(N+1):
    for j in a:
        if i - j <= 0:
            continue
        else:
            dp[i] += dp[i-j]

print(dp[N] % MOD)
