import numpy as np
N, K = map(int, input().split())
MOD = 998244353

mark = [0]*(N+1)
for i in range(K):
    l, r = map(int, input().split())
    for i in range(l, r+1):
        mark[i] = 1

count = [0]*(N+1)
count[1] = 1
for i in range(1, N+1):
    for k in range(N+1):
        if mark[k] > 0 and (i + k) <= N:
            count[i + k] = (count[i + k] + count[i]) % MOD

print(count[N])


