divnum = 998244353
n, k = map(int, input().split())
set_A = set()
for _ in range(k):
	a, b = map(int, input().split())
	set_A = set_A | set(range(a, b+1))
ans_list = [0]*(n+1+max(set_A))
ans_list[1] = 1
for i in range(1,n):
	for j in set_A:
		ans_list[i+j] = (ans_list[i+j]+ans_list[i])%divnum
print(ans_list[n])