#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const ll MOD = 998244353;

int main() {
	cin.tie(0)->sync_with_stdio(false);
	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, 0);
	dp[0] = 1;
	dp[1] = -1;
	REP(i, n) {
		dp[i] = ((dp[i] % MOD) + MOD) % MOD;
		dp[i + 1] = (dp[i + 1] + dp[i]) % MOD;
		REP(j, k) {
			if (i + l[j] < n) dp[i + l[j]] += dp[i];
			if (i + r[j] + 1 < n) dp[i + r[j] + 1] -= dp[i];
		}
	}
	cout << dp[n - 1] << '\n';
	return 0;
}
