int main() {
	//cout << "" << endl; // prints
	int N, K;
	const int mod = 998244353;
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N >> K;
	int dp[N+1];
		dp[0] = 0;
		dp[1] = 1;
	for(int a = 2; a <= N; a++){
		dp[a] = 0;
	}
	int LR[K+1][3];
	int LRmax = 0;
	int LRmin = 200001;
	bool TF[N+1];
	for(int i = 0; i <= N; i++){
		TF[i] = false;
	}
	for(int i = 1; i <= K; i++){
		cin >> LR[i][1] >> LR[i][2];
		for(int j = LR[i][1]; j <= LR[i][2]; j++){
			TF[j] = true;
		}
		if(LR[i][1] < LRmin){
			LRmin = LR[i][1];
		}
		if(LR[i][2] > LRmax){
			LRmax = LR[i][2];
		}
	}

	for(int i = 1; i <= N; i++){
		for(int j = i - LRmax; j < i; j++){
			if(TF[i - j] == true){
				dp[i] += dp[j];
			}
			dp[i] = dp[i] % mod;
		}
	}
	cout << dp[N] << endl;
	return 0;
}