import sys
sys.setrecursionlimit(2*10**5+10)
n,k=map(int, input().split())
a=[]
for i in range(k):
	l,r=map(int, input().split())
	for j in range(l,r+1):
		a.append(j)
dp=[-1]*(n+1)
def dfs(m):
	if m<=0: return 0
	if m==1: return 1
	if dp[m]>=0: return dp[m]
	ans=0
	for i in a:
		ans+=dfs(m-i)
		ans%=998244353
		dp[m]=ans
	return ans
print(dfs(n))