#include<cstdio>
int n,k,l[15],r[15];
long long f[200005],mod=998244353,sm[200005];
long long query(int l,int r)
{
	if(r<0)
		return 0;
	if(l<=0)
		return sm[r];
	return ((sm[r]-sm[l-1])%mod+mod)%mod;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;++i)
		scanf("%d%d",&l[i],&r[i]);
	f[0]=sm[0]=1;
	--n;
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=k;++j)
			f[i]+=query(i-r[j],i-l[j]),f[i]%=mod;
		sm[i]=(sm[i-1]+f[i])%mod;
	}
	printf("%d",f[n]);
}