n,k = input().split()
goal = int(n)
loup = int(k)
total = set()
dp = [0] * (goal + 1)
dp[0] = 1



#集合の作成
for k in range(loup):
	a,b = map(int, input().split())
	l = set(range(a,b+1))
	total = total | l

#main
for i in range(1,goal+ 1):
	for n in range(1,max(total) + 1):
		if n not in total:
			continue
        
		if i-n >= 0:
			dp[i] = dp[i] + dp[i-n]

print(dp[goal - 1] % 998244353)