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