n,k = map(int,raw_input().split())
jis = [map(int, raw_input().split()) for _ in range(k)]
dp = [0 for _ in range(n)]
dp[0] = 1
mod = 998244353
for i in range(1,n):
	for u,v in jis:
		for w in range(u,v+1):
			if i-w>=0:
				dp[i] += dp[i - w]
				dp[i] %= mod
print dp[n-1]