N, K = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(K)]

MOD = 998244353
P = set()

for l, r in LR:
    _ = [P.add(i) for i in range(l, r + 1)]


s = [0 for _ in range(N + 1)]

s[min(P)] = 1

for d in range(N + 1):
    if s[d] == 0:
        continue
    for p in P:
        if d + p < N + 1:
            s[d + p] = s[d + p] % MOD + s[d]

print(s[N] % MOD)
