#include<bits/stdc++.h>
using namespace std;
#define M 998244353
typedef long long int LL;
int main(){
	int n,k;
	cin>>n>>k;
	pair<int,int> s[k];
	for(int i=0;i<k;i++) cin>>s[i].first>>s[i].second;
	sort(s,s+k);
	LL dp[n+1];
	for(int i=0;i<=n;i++) dp[i]=0LL;
	dp[n-1]=1LL;
	for(int i=n-2;i>=0;i--){
		for(int j=0;j<k;j++){
			if(i+s[j].first>=n) break;
			int up;
			up=min(i+s[j].second+1,n);
			dp[i]=(M+dp[i]+dp[i+s[j].first]-dp[up])%M;
		}
		dp[i]=(dp[i]+dp[i+1])%M;
	}
	cout<<(dp[0]-dp[1]+M)%M<<"\n";
}