K, N = map(int, input().split())
num_list = []
for i in range(N):
    L, R = map(int, input().split())
    num_list += list(range(L, R+1))
    
num_set = set(sorted(num_list))
counting = [0 for i in range(K+1)]
counting[1]=1
for i in range(2, K+1): 
    for n in num_set:
        if i-n > 0:
            counting[i] += counting[i-n]
print(counting[K]%998244353)