#include<bits/stdc++.h>
using namespace std;
const int N=200005,mod=998244353;
int n,k,l[N],r[N],dp[N]={1},s[N]={1};
int main()
{
	scanf("%d%d",&n,&k);
	n--;
	for(int i=1;i<=k;i++)
		scanf("%d%d",&l[i],&r[i]);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=k;j++)
		{
			if(l[j]>i)
				continue;
			int x=max(0,i-r[j]),y=i-l[j];
			int v=(s[y]+mod-s[x-1])%mod;
			dp[i]=(dp[i]+v)%mod;
		}
		s[i]=(s[i-1]+dp[i])%mod;
	}
	printf("%d\n",dp[n]);
	return 0;
}