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

const int N = 2e5 + 5;
ll dp[N];
void solve() {
	ll n, k;
	cin >> n >> k;
	vector<pair<ll, ll>>v(k);
	for (int i = 0; i < k; i++) {
		cin >> v[i].first >> v[i].second;
	}
	sort(v.begin(), v.end());
	ll start = v[0].first;
	ll end = v[0].second;
	vector<pair<ll, ll>>keep;
	for (int i = 1; i < k; i++) {
		if (v[i].first - 1 > end) {
			keep.push_back({start, end});
			start = v[i].first;
			end = v[i].second;
		}
		else {
			end = max(end, v[i].second);
		}
	}
	keep.push_back({start, end});
	ll prefix = 0;
	dp[1] = 1;
	for (auto y : keep) {
		// cout << y.first << " " << y.second << "\n";
		dp[1 + y.first] += dp[1];
		dp[1 + y.first] %= M;
		if (1 + y.second + 1 < N) {
			dp[1 + y.second + 1] -= dp[1];
			if (dp[1 + y.second + 1] < 0) {
				dp[1 + y.second + 1] += M;
			}
		}
	}
	for (ll i = 2; i < n + 1; i++) {
		dp[i] += prefix;
		dp[i] = (dp[i] + M) % M;
		prefix = dp[i];
		for (auto y : keep) {
			dp[i + y.first] += dp[i];
			dp[i + y.first] = (dp[i + y.first] + M) % M;
			if (i + y.second + 1 < N) {
				dp[i + y.second + 1] -= dp[i];
				if (dp[i + y.second + 1] < 0) {
					dp[i + y.second + 1] += M;
				}
			}
		}
	}
	cout << dp[n];
}


int main() {
	int ntc = 1;
	while (ntc--) {
		solve();
	}
}