#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=998244353;
int f[200005],l[25],p[25],q[200005];
signed main(){
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=k;i++){
		cin>>l[i]>>p[i];
	}
	f[1]=q[1]=1;
	for(int i=2;i<=n;i++){
		for(int j=1;j<=k;j++){
			f[i]+=((q[max(i-l[j],0ll)]-q[max(i-p[j]-1,0ll)])%mod+mod)%mod;
			f[i]%=mod;
		}
		q[i]=q[i-1]+f[i];
		q[i]%=mod;
	}
	cout<<f[n]<<endl;;
	return 0;
}