#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;

	int l[k], r[k];

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

	long long dp[n+1];
	long long dpsum[n+1];
	for(int i=0;i<=n;i++){
		dp[i] = 0;
		dpsum[i] = 0;
	}
	dp[1] = 1;
	dpsum[1] = 1;
	for(int i=1;i<=n;i++){
		for(int j=0;j<k;j++){
			int li = i - r[j];
			int ri = i - l[j];
			if(ri < 1) continue;
			if(li < 1) li = 1;
			dp[i] += (dpsum[ri] - dpsum[li-1]);
			dp[i] %= 998244353;
		}
		dpsum[i] = (dpsum[i-1] + dp[i]);
	}
  	cout << dp[n] << endl;
  	return 0;
}