N, K = map(int, input().split())
S = []
while K !=0:
    L, R = map(int, input().split())
    S += [[L,R]]
    K -= 1
A = [1]
n = 1
while n <= N - 1:
    for i in S:
        s = sum(A[n - i] for s in S for i in range(s[0], s[1] + 1) if n - i >= 0) % 998244353
        A += [s]
        s = 0
        n += 1
print(A[N-1])