#include<bits/stdc++.h>
#define int long long
#define P 998244353
using namespace std;
int n,K,a[200001],s[200001],l[11],r[11];
signed main(){
	cin>>n>>K;
	for(int i=1;i<=K;i++)cin>>l[i]>>r[i];
	a[1]=1;s[1]=1;s[2]=P-1;
	for(int i=1;i<=n;i++){
		a[i]=a[i-1]+s[i];a[i]%=P;
		for(int j=1;j<=K;j++){
			if(l[j]+i<=n)s[l[j]+i]=(s[l[j]+i]+a[i])%P;
			if(r[j]+i+1<=n)s[r[j]+i+1]=(s[r[j]+i+1]-a[i]+P)%P;
		}
	}
	printf("%lld\n",a[n]);
	return 0;
}