#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int mod = 998244353;
int n, k, l[10], r[10], a[200001], b[200002] = { 0, 1, -1 };

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

	for (int i = 1; i < n; ++i) {
		a[i] = (a[i - 1] + b[i]) % mod;
		for (int j = 0; j < k; ++j) {
			int x, y;
			x = min(n + 1, i + l[j]);
			y = min(n + 1, i + r[j] + 1);
			b[x] += a[i];
			b[x] %= mod;
			b[y] -= a[i];
			b[y] %= mod;
		}
	}
	a[n] = (a[n - 1] + b[n]) % mod;

	if (a[n] < 0)
		a[n] += mod;
	cout << a[n] << endl;
}
