mod=998244353
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
lr=[]
for i in range(k):
	l,r=map(int,input().split())
	lr.append((l,r))
lr.sort()

cnt=[0]*n
cnt[0]=1
dp=[0]*n
for i in range(n-1):
	cnt[i]+=dp[i]
	for x,y in lr:
		if i+x<n:
			dp[i+x]+=cnt[i]
			dp[i+x]%=mod
		if i+y<n-1:
			dp[i+y+1]-=cnt[i]
			dp[i+y+1]%=mod
	dp[i]%=mod
	cnt[i]%=mod
	dp[i+1]+=dp[i]
print((cnt[-1]+dp[-1])%mod)