#include<bits/stdc++.h>
#define mod 998244353
#define maxn 200005
using namespace std;
int n,k;
long long a[maxn],sum[maxn];
int l[15],r[15];
long long getsum(int pos)
{
	if (pos<0) return 0;
	return sum[pos];
}
int main()
{
	cin>>n>>k;
	for (int i=1;i<=k;i++)
		cin>>l[i]>>r[i];
	a[1]=sum[1]=1;
	for (int i=2;i<=n;i++)
	{
		for (int j=1;j<=k;j++)
		{
			a[i]+=(getsum(i-l[j])-getsum(i-r[j]-1));
			a[i]=(a[i]%mod+mod)%mod;
		}
		sum[i]=((sum[i-1]+a[i])%mod+mod)%mod;
	}
	cout<<a[n]<<endl;
}