MOD = 998244353
N, K = map(int, input().split())
kukan = [list(map(int, input().split())) for _ in range(K)]
step = [0 for _ in range(K)]
ans = [0] * (2 * N)
ans[N] = 1
for i in range(N):
    for k in range(K):
        step[k] += (ans[N + i - kukan[k][0]] - ans[N + i - kukan[k][1] - 1])
    ans[N + i] += sum(step) % MOD
print(ans[-1])

