n,k=map(int,input().split())
arr=[]
for _ in range(k):
	arr.append(list(map(int,input().split())))
pref=[0]*(n+1)
dp=[0]*(n+1)
dp[0]=1
pref[0]=1
for i in range(1,n):
	for j in range(k):
		if(arr[j][1]<=i):
			dp[i]=(dp[i]+pref[i-arr[j][0]]-pref[i-arr[j][1]-1])%998244353
		elif(arr[j][0]<=i):
			dp[i]=(dp[i]+pref[i-arr[j][0]])%998244353
	pref[i]=(pref[i-1]+dp[i])%998244353
print(dp[n-1])