#include <bits/stdc++.h>
using namespace std;
const int mod=998244353;
int n,k,f[200005],s[200005],l[25],r[25];
int main(){
	cin>>n>>k;
	for(int i=1;i<=k;i++)cin>>l[i]>>r[i];
	f[1]=s[1]=1;
	for(int i=2;i<=n;i++){
		for(int j=1;j<=k;j++){
			if(l[j]>=i)continue;
			int o=l[j],oo=min(r[j],i-1);
			f[i]=(0ll+f[i]+s[i-o]-s[i-oo-1]+mod)%mod;
		}
		s[i]=s[i-1]+f[i];
		s[i]%=mod;
	}
	cout<<f[n];
    return 0;
}