#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int main() {
	int n, k; cin>>n>>k;
	vector<pair<int, int>> a(k);
	for(int i = 0; i < n; i++){
		cin>>a[i].first>>a[i].second;
	}
	vector<int> dp(n), pref(n);
	dp[0] = pref[0] = 1;
	for(int i = 1; i < n; i++){
		for(pair<int, int> p: a){
			int l = max(0, i - p.second);
			int r = i - p.first;
			if(l <= r){
				dp[i] += pref[r];
				if(l >= 1) dp[i] -= pref[l-1];
				dp[i] %= mod;
				if(dp[i] < 0) dp[i] += mod;
			}
		}
		pref[i] = (pref[i - 1] + dp[i]) % mod;
	}
	cout<<dp[n - 1]<<endl;
}