#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int N, K; cin >> N >> K; 
	int L[12], R[12]; 
	for(int i = 0; i < K; i++) cin >> L[i] >> R[i]; 
	long long dp[200010] = {}; 
	long long DP[200010] = {}; 
	dp[1] = 1; DP[1] = 1; 
	long long mod = 998244353; 
	for(int i = 2; i <= N; i++){
		for(int j = 0; j < K; j++){
			int l = i - R[j]; int r = i - L[j]; 
			if(r < 0) continue; 
			else if(l <= 0) dp[i] += DP[r]; 
			else dp[i] += DP[r] - DP[l-1]; 
		}
		dp[i] += mod * 10; 
		dp[i] %= mod; 
		DP[i] = (DP[i-1] + dp[i]) % mod; 
	}
	cout << dp[N] << "\n"; 
}