#include <bits/stdc++.h>

using namespace std;

const int P = 998244353;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n, k;
	cin >> n >> k;

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

	vector<long long> dp(n + 1);
	vector<long long> pre(n + 1);

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

	cout << dp[n] << '\n';

	return 0;
}
