def main():
	N, K = [int(a) for a in input().split(" ")]
	p = 998244353
	interval = []
	for i in range(K):
		L, R = [int(b) for b in input().split(" ")]
		interval.append({
			"left": L,
			"right": R
		})
	interval.sort(key=lambda itv: itv["left"])

	w = [0, 1]
	for i in range(2, N + 1):
		c = 0
		for j in range(len(interval)):
			if i - interval[j]["left"] <= 0:
				break
			if i - interval[j]["left"] > 0 and i - interval[j]["right"] <= 0:
				for k in range(interval[j]["left"], i):
					c = (c + w[i - k]) % p
			else:
				for k in range(interval[j]["left"], interval[j]["right"] + 1):
					c = (c + w[i - k]) % p
		w.append(c)
	print(w[-1])

main()