#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
//これで通ったら訳がわからない
int main() {
	ll N, K;
	cin >> N >> K;
	ll L[K], R[K];
	for(int i = 0; i < K; i++) cin >> L[i] >> R[i];

	vector<ll> v;
	for(int i = 0; i < K; i++)
		for(; L[i] <= R[i]; L[i]++) v.push_back(L[i]);
	sort(v.begin(), v.end());

	ll dp[N] = {};
	dp[0] = 1;
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < v.size(); j++) {
			if(i + v[j] > N) break;
			dp[i + v[j]] += dp[i];
			dp[i + v[j]] %= mod2;
		}
	}
	cout << dp[N - 1] << "\n";
	return 0;
}