n,k=map(int,input().split())
dp=[0]*n
dp[0]=1
mod=998244353
csdp=0
s=[]
for _ in range(k):
	l,r=map(int,input().split())
	s.append([-r,-l])
for i in range(1,n):
	for j in range(k):
		if s[j][0]>=0:csdp=(csdp-dp[s[j][0]])%mod
		s[j][0]+=1
		s[j][1]+=1
		if s[j][1]>=0:csdp=(csdp+dp[s[j][1]])%mod
	dp[i]=csdp
print(dp[n-1])