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

typedef long long ll;
const int p = 998244353;
const int maxn = 2e5 + 5;

int n, k;
int l[maxn], r[maxn];
ll f[maxn], sum[maxn];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n >> k;
	k = min(10, k);
	for(int i = 1; i <= k; ++i) cin >> l[i] >> r[i];
	
	f[1] = sum[1] = 1;
	for(int i = 2; i <= n; ++i){
		for(int j = 1; j <= k; ++j){
			int a = l[j], b = r[j];
			if(a >= i) continue;
			a = i - a;
			b = max(0, i - b - 1);
			f[i] = (f[i] + sum[a] - sum[b] + p) % p;
		}
		sum[i] = (sum[i-1] + f[i]) % p;
	}
	cout << f[n];
}