#include<bits/stdc++.h>
#define mod 998244353
using namespace std;
typedef long long int ll;
typedef long double ld;
const int maxn=2E5+5;
ll n,k,l[maxn],r[maxn],f[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>k;
	for(int i=1;i<=k;++i)
		cin>>l[i]>>r[i];
	f[1]=1;
	ll s=0;
	for(int i=2;i<=n;++i)
	{
		for(int j=1;j<=k;++j)
		{
			if(i-l[j]>=1)
				s=(s+f[i-l[j]])%mod;
			if(i-r[j]-1>=1)
				s=(s-f[i-r[j]-1])%mod;
		}
		f[i]=s;
	}
	cout<<(f[n]%mod+mod)%mod<<endl;
	return 0;
}
