#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 200010;
const long long P = 998244353;
int N, K;
int L[20], R[20];
long long dp[MAX_N], sums[MAX_N];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin >> N >> K;
	for (int i = 0; i < K; i++)
		cin >> L[i] >> R[i];
	
	dp[N] = 1;
	sums[N] = 1;
	
	for (int i = N - 1; i >= 1; i--) {
		for (int j = 0; j < K; j++) {
			int a = min(i + L[j], N + 1), b = min(i + R[j], N);
			dp[i] = (dp[i] + sums[a]) % P;
			dp[i] = (dp[i] - sums[b + 1] + P) % P;
		}
		sums[i] = (dp[i] + sums[i + 1]) % P;
	}
	
	cout << dp[1] << "\n";
	
	return 0;
}
