#Naive Implementation
N, K = map(int, input().split())
MOD = 998244353

p = []

for i in range(K):
	l, r = map(int, input().split())
	
	p = p + list(range(l, r+1))
	
dp = [0] * (N+1)
dp[1] = 1

for i in range(1, N+1):
	for move in p:
		if i + move > N:
			continue
		dp[i+move] = dp[i] + dp[i+move]	

print(dp[N])