N, K = map(int, input().split())
S = []
while K !=0:
    L, R = map(int, input().split())
    S += [i for i in range(L,R+1)]
    K -= 1

A = [1]
n = 1
while n <= N - 1:
    for i in S:
        s = sum(A[n - i] for i in S if n - i >= 0)% 998244353
        A += [s]
        s = 0
        n += 1
print(A[N-1])