import math
K, N = map(int, input().split())
num_set = []
for i in range(N):
    L, R = map(int, input().split())
    num_set += list(range(L, R+1))
#print(num_set)
count_log = [-1 for i in range(K)]

def recursion(n, count):
    if n == 0:
        return 1
    elif n < 0:
        return 0
    for i in num_set:
        #print(n, i, n-i)
        if n-i < 0:
            count += 0
            continue
        if count_log[n-i] != -1:
            r = count_log[n-i] 
        else:
            r = recursion(n-i, 0)
            count_log[n-i] = r 
        count += r
    return count

output = recursion(K-1, 0)        
print(output%998244353)