#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int q,x,i,k,l[N],r[N],j,M=998244353;
long long dp[N*2],n,ans,s[N*2];
int main()
{
	scanf("%d %d",&n,&k);
	for(i=1;i<=k;++i)
		scanf("%d %d",&l[i],&r[i]);
	dp[n]=1;
	s[n]=1;
	for(i=n-1;i>=0;--i)
	{
		for(j=1;j<=k;++j)
			dp[i]=(dp[i]+s[i+l[j]]-s[i+r[j]+1])%M;
		s[i]=(dp[i]+s[i+1])%M;
	}
	cout<<(dp[1]%M+M)%M<<endl;
}
