N,K=list(map(int,input().split()))
method=[]
for x in range(K):
	a,b=list(map(int,input().split()))
	method += list(range(a,b+1))
method.sort()
#print(method)
nums=[0]*(N+1)
nums[1]=1
for x in range(1,N):
	for step in method:
		if x+step>N:
			break
		nums[x+step]+=nums[x]
		#print(nums[x+step],"+=",nums[x])
print(nums[N]%998244353)
#print(nums)