# range update
# point query

M = 998244353

# on demand
class SegmentTreeNodeOD:
	def __init__(self, start, end):
#		print("s", start, end)
		self.value = 0
		self.start = start
		self.end = end
		self.width = end - start
		self.left = None
		self.right = None
	
	def add(self, start, end, value):
		if self.start >= start and self.end <= end:
			self.value = (self.value + value) % M
		elif self.width > 1 and (self.start < end and start < self.end):
			if self.left == None:
				w2 = self.width // 2
				self.left = SegmentTreeNodeOD(self.start, self.start + w2)
				self.right = SegmentTreeNodeOD(self.start + w2, self.end)
			self.left.add(start, end, value)
			self.right.add(start, end, value)
	
	def sum(self, index):
		s = 0
		if self.start <= index and index < self.end:
			s = (s + self.value) % M
			if self.left != None:
				s = (s + self.left.sum(index) + self.right.sum(index)) % M
		return s
	
class SegmentTreeOD:
	def __init__(self, n):
		width = 1
		while width < n:
			width *= 2
		self.root = SegmentTreeNodeOD(0, width)
		self.root.value = 0
	
	def add(self, start, end, value):
		self.root.add(start, end, value)
	
	def sum(self, index):
		return self.root.sum(index)
	
N, K = map(int, input().split())

sects = []
for _ in range(K):
	sects.append(tuple(map(int, input().split())))

st = SegmentTreeOD(N + 1)
st.add(1, 2, 1)

for i in range(N):
#	print(st.to_list())
	count = st.sum(i)
	for R, L in sects:
		st.add(i + R, i + L + 1, count)

#print(st.to_list())

print(st.sum(N))
