p = 998244353
N,K = [int(i) for i in input().split()]
L = [0]*(N+1)
L[1] = 1
nums = []
for _ in range(K):
    a,b = [int(i) for i in input().split()]
    for i in range(a,b+1):
        nums.append(i)
for i in range(2,N+1):
    for j in range(1,i):
        if i-j in nums:
            L[i] = (L[i] + L[j])%p
print(L[-1])