#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
int main(){
	ll n, k, mod = 998244353;
	cin >> n >> k;
	ll l[k], r[k], a[n];
	for (int i = 0; i < k; i++) cin >> l[i] >> r[i];
	for (int i = 0; i < n; i++){
		if (i == 0) a[i] = 1;
		else if (i == 1) a[i] = 0;
		else a[i] = a[i - 1];
		for (int j = 0; j < k; j++){
			if (i - l[j] >= 0) (a[i] += a[i - l[j]]) %= mod;
			if (i - r[j] - 1 >= 0) (a[i] += mod - a[i - r[j] - 1]) %= mod;
		}
	}
	printf("%lld\n", a[n - 1]);
}