mod=998244353
def countWays(arr,m,n):
	count=[0 for i in range(n+1)]
	count[0]=1
	for i in range(1,n+1):
		for j in range(m):
			if (i>=arr[j]):
				count[i]+=(count[i-arr[j]])
	return count[n-1]
	
	
	
	

s=set()
n,k=map(int,input().split())
for i in range(k):
	a,b=map(int,input().split())
	for i in range(a,b+1):
		s.add(i)
		

arr=list(s)
m=len(arr)

print(countWays(arr,m,n)%mod)


