#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 998244353;
int N, K;
vector<int> L, R;
int main() {
	cin >> N >> K;
	L.resize(K);
	R.resize(K);
	for (int i = 0; i < K; ++ i) {
		cin >> L[i] >> R[i];
	}
	vector<ll> hoge(N);
	hoge[0] = 1;
	hoge[1] = mod-1;
	ll s = 0;
	for (int i = 0; i < N; ++ i) {
		(s += hoge[i]) %= mod;
		for (int j = 0; j < K; ++ j) {
			int x = i + L[j];
			int y = i + R[j] + 1;
			if (x < N) (hoge[x] += s) %= mod;
			if (y < N) (hoge[y] += mod - s) %= mod;
		}
	}
	cout << s << endl;
}
