import math
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))
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:
        if n-i < 0:
            count += 0
            continue
        elif n-i == 0:
            count += 1
            continue
        elif 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)