N,K=map(int,input().split())
D=set()
for _ in range(K):
	L,R=map(int,input().split())
	for l in range(L,R+1):
		D.add(l)
	
MOD = 998244353

dp = [ 0 for _ in range(N+1) ]
dp[1] = 1

# print(D)

# これでは、データによってはO(n ** 2)でTLE
for n in range(1,N+1):
	for d in D:
		if n+d <= N and dp[n]:
			dp[n+d] += dp[n]
			# print("遷移",n,d,"値",dp[n+d])

# d[n+d]

# print(dp)
print(dp[N] % MOD)