N, K = map(int, input().split(" "))
mod = 998244353

paths = []
for i in range(K):
    L, R = map(int, input().split(" "))
    paths += list(range(L, R+1))

log = [0] * N
for i in range(N):
    if i == 0:
        log[i] = 1
    for d in paths:
        if i - d >= 0:
            log[i] += log[i-d] % mod

print(log[N-1] % mod)
