N, K = map(int, input().split())
S = set()

MOD = 998244353
for _ in range(K):
    L, R = map(int, input().split())
    S |= set(range(L, R + 1))
# print(f'{S=}')

DP = [0] * (N + 1)
DP[0] = 0
DP[1] = 1

for i in range(1, len(DP)):
    for s in S:
        if i - s > 0:
            DP[i] += DP[i - s]
    DP[i] %= MOD
# print(f'{DP=}')
print(DP[-1])
