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

const int mod = 998244353;

int L[20], R[20];
long long dp[200010];
long long sum[200010];

int main () {
	int n, k; cin >> n >> k;
	for (int i = 0; i < k; i++) {
		cin >> L[i] >> R[i];
	}
	dp[1] = sum[1] = 1;
	for (int i = 2; i <= n; i++) {
		for (int j = 0; j < k; j++) {
			if (i - L[j] <= 0) continue;
			int r = i - L[j], l = i - R[j];
			if (l < 0) l = 1;
			dp[i] = (dp[i] + sum[r] - sum[l - 1] + mod) % mod;
		}
		sum[i] = (sum[i - 1] + dp[i]) % mod;
	}
	cout << dp[n] << endl;
	return 0;
}
