#include <bits/stdc++.h>
#define ll long long
#define mod 998244353
using namespace std;
const int maxn=2e5+10;
ll dp[maxn];
ll sum[maxn];
ll x[15];
ll y[15];
int main() {
	int n,k;
	cin>>n>>k;
	int pos=0;
	for(int i=0;i<k;i++) {
		cin>>x[i]>>y[i];
	}
	//cout<<m<<endl;
	//for(int i=0;i<k*2;i++) cout<<a[i]<<" ";
	//cout<<endl;
	memset(dp,0,sizeof(dp));
	dp[1]=1;
	dp[0]=0;
	sum[1]=1;
	sum[0]=0;
	for(int i=2;i<=n;i++) {
		for(int j=0;j<k;j++) {
			if(y[j]<i) {
				dp[i]=(dp[i]+sum[i-x[j]]-sum[i-y[j]-1])%mod;
			}else if(x[j]<i){
				dp[i]=(dp[i]+sum[i-x[j]]-sum[0])%mod;
			}
		}
		sum[i]=sum[i-1]+dp[i];
		//cout<<dp[i]<<endl;
	}
	cout<<dp[n]<<endl;
}