#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 998244353;
int main(){
	int n,k;
	cin >> n >> k;

	vector<ll> dp(n+1,0);
	vector<ll> accum(n+1,0);

	vector<int> l(k);
	vector<int> r(k);

	for(int i = 0;i < k;i++){
		cin >> l[i] >> r[i];
	}

	dp[1] = 1;
	accum[1] = 1;
	for(int i = 2;i <= n;i++){
		for(int j = 0;j < k;j++){
			dp[i] += (accum[max(0,i-l[j])] - accum[max(0,i-r[j]-1)] + MOD) % MOD;
			dp[i] %= MOD;
		}
		accum[i] = (dp[i] + accum[i-1]) % MOD;
	}

	cout << dp[n] << endl;
}
