#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int MOD = 998244353;

int main() {
	int n, k; cin >> n >> k;
	vector<int> L(k), R(k);
	vector<long long> cnt(n + 1);
	for (int i = 0; i < k; ++i) {
		cin >> L[i] >> R[i];
		++cnt[L[i]];
		--cnt[min(n, R[i] + 1)];
	}
	for (int i = 1; i < n; ++i) {
		(cnt[i] += cnt[i - 1]) %= MOD;
		for (int j = 0; j < k; ++j) {
			(cnt[min(n, i + L[j])] += cnt[i]) %= MOD;
			(cnt[min(n, i + R[j] + 1)] -= cnt[i]) %= MOD;
		}
	}
	cout << (cnt[n - 1] + MOD) % MOD << endl;

	return 0;
}
