N, K = map(int, input().split())
S = []
for i in range(K):
    L, R = map(int, input().split())
    S.append([L,R])
A = [1]
for n in range(1,N):
    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.append(s)
        s = 0
print(A[N-1])