MOD = 998244353
n, k = map(int, input().split())
seg = [list(map(int, input().split())) for _ in range(k)]
dp = [0 for _ in range(n+1)]
dp[1] = 1
cum = [0 for _ in range(n+1)]
cum[1] = 1
for i in range(2, n+1):
	for l, r in seg:
		r, l = max(i-l, 0), max(i-r-1, 0)
		dp[i] += cum[r] - cum[l]
		dp[i] %= MOD
	cum[i] = cum[i-1] + dp[i]
	cum[i] %= MOD
print(dp[n])