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