#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const int MOD=998244353;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int l[20],r[20];
ll dp[300000],sdp[300000];

int main(){
	int n,K;cin>>n>>K;
	rep(i,K){
		scanf("%d%d",&l[i],&r[i]);
	}
	dp[0]=1;sdp[1]=1;
	for(int i=1;i<n;i++){
		rep(j,K){
			(dp[i]+=(sdp[max(0,i-l[j]+1)]+MOD-sdp[max(0,i-r[j])]))%=MOD;
		}
		//~ cout<<i<<' '<<dp[i]<<endl;
		sdp[i+1]=(sdp[i]+dp[i])%MOD;
	}
	cout<<dp[n-1]<<endl;
}