mmm=998244353
def countWays(arr, m, N): 

	count = [0 for i in range(N + 1)] 
	
	# base case 
	count[0] = 1
	
	for i in range(1, N + 1): 
		for j in range(m): 

			if (i >= arr[j]): 
				count[i] =(count[i]+ count[i - arr[j]] )%mmm
	
	return count[N] 
	
a,b=map(int,input().split())
s=set()
arr=[]
for i in range(b):
    x,y=map(int,input().split())
    for j in range(x,y+1):
        arr.append(j)
            
    # arr = [1, 5, 6] 
# print(arr)
m = len(arr) 
N = a-1
print(countWays(arr, m, N)) 
			
# This code is contributed by Anant Agarwal. 
