#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 998244353;

ll R[11], L[11], S[800010];

int main() {
	int N, K;
	cin >> N >> K;
	
	for (int i = 0;i < K;i++) {
		cin >> L[i] >> R[i];
	}
	for (int i = 0;i < 800010;i++)S[i] = 0;
	S[1] = 1, S[2] = -1;
	for (int i = 1;i <= N;i++) {
		S[i] += S[i - 1];
		for (int k = 0;k < K;k++) {
			S[i + L[k]] += S[i];
			S[i + R[k] + 1] += -S[i];

			S[i + L[k]] %= MOD;
			S[i + R[k] + 1] %= MOD;
		}
	}
	S[N] %= MOD;
	S[N] += MOD;
	cout << S[N] % MOD << endl;
}