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))

counted = {}
def recursion(n):
    count = 0
    if n == 0:
        return 1
    elif n < 0:
        return 0
    for i in num_set:
        if n-i < 0:
            continue
        elif n-i in counted:
            r = counted[n-i]
        else:
            r = recursion(n-i)
            counted[n-i] = r 
        count += r
    return count

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