#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	constexpr Int MOD = 998244353;
	int N, K;
	cin >> N >> K;
	vector<int> L(K), R(K);
	for (int i = 0; i < K; ++i) {
		cin >> L[i] >> R[i];
	}

	vector<Int> d(N + 10, 0);
	vector<Int> a(N + 10, 0);
	a[1] = 1;
	for (int i = 1; i <= N; ++i) {
		(d[i] += d[i - 1]) %= MOD;
		(a[i] += d[i]) % MOD;
		for (int k = 0; k < K; ++k) {
			if (i + L[k] > N) { continue; }
			int r = min(N, i + R[k]) + 1;
			(d[i + L[k]] += a[i]) %= MOD;
			(d[r] += MOD - a[i]) %= MOD;
		}
	}
	cout << a[N] % MOD << "\n";

	return 0;
}
