def dfs(q, here, result):
	# print('q,here1: ', q, here, result)
	if len(q) == 0:
		print(result % 998244353)
		return result
	for i in num:
		# print('i, here: ', i, here)
		if i + here <= n:
			q.append(i + here)
		else:
			break
	# print('q,here2,result: ', q, here, result)
	here = q.pop()
	if here == n:
		result += 1
	dfs(q, here, result)

from collections import deque

n, k = (int(each) for each in input().split())
lr = []
global result
global num
global q
result = 0
num = []
for each in range(k):
	lr = [int(each) for each in input().split()]
	for i in range(lr[0], lr[1]+1):
		num.append(i)

q = deque([1])
dfs(q, 1, result)