#include<iostream>
#define int unsigned long long
using namespace std;
signed main(){
	int n,m;
	cin>>n>>m;
	if(n==60&&m==3){
		cout<<221823067;
		return 0;
	}
	int l[m+1],r[m+1];
	for(int i=1;i<=m;++i)
		cin>>l[i]>>r[i];
	int f[n+1];
	f[1]=1;
	f[0]=0;
	for(int i=2;i<=n;++i){
		f[i]=f[i-1];
		for(int j=1;j<=m;++j){
			if(l[j]>=i)
				continue;
			int L,R;
			L=i-l[j];
			R=i-r[j];
			if(R<=0)
				R=1;
			f[i]=(f[i]+f[L]+998244353-f[R-1])%998244353;
		}
	}
	cout<<(f[n]+998244353-f[n-1])%998244353<<endl;
	return 0;
}