#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const int mod = 998244353;

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> l(k), r(k);
	rep(i, k) cin >> l[i] >> r[i];
	vector<ll> dp(n + 1);
	vector<ll> dps(n + 1);
	dp[1] = 1;
	dps[1] = 1;
	for (int i = 2; i <= n; i++) {
		rep(j, k) {
			int li = i - r[j];
			int ri = i - l[j];
			if (ri < 0) continue;
			li = max(li, 1);
			dp[i] += (dps[ri] - dps[li - 1] + mod) % mod;
		}
		dps[i] = (dps[i - 1] + dp[i] + mod) % mod;
	}
	cout << (dp[n] + mod) % mod << endl;
	return 0;
}
