MOD = 998244353
N, K = map(int, input().split())
S = set()
for _ in range(K):
    L, R = map(int, input().split())
    for j in range(L, R + 1):
        if j not in S:
            S.add(j)
C = [0] * N
C[0] = 1
for i in range(N):
    for s in S:
        if i + s < N:
            C[i + s] += C[i]
print(C[N - 1] % MOD)