#include <bits/stdc++.h>
using namespace std;
 
#define MOD 998244353
 
int main(){
	int n, k, sz, l, r, ans=0;
	cin >> n >> k;
	vector < int > dp(n+10,0);
	vector < pair < int , int > > vpp;
	while(k--){
		cin >> l >> r;
		r++;
		vpp.push_back({l,r});
	}
	dp[0] = 1; dp[1] = -1;
	for(int i=0;i<n;i++){
		if(i > 0) dp[i] = (dp[i]+dp[i - 1])%MOD;
		for(auto lol : vpp){
			tie(l,r) = lol;
			if (i + l < n) dp[i + l] = (dp[i+l]+dp[i])%MOD;
			if (i + r < n) dp[i + r] = (dp[i+r]-dp[i])%MOD;
		}
	}
	//for(int i=0;i<n;i++) cout << i << " = " << dp[i] << endl; 
	cout << (MOD+dp[n-1])%MOD << endl;
	return 0;
}