#include <bits/stdc++.h>
#define rei register int
#define int long long
using namespace std;
const int maxn = 200010,mod = 998244353;
int n,k;
int l[maxn],r[maxn];
int sum[maxn],dp[maxn];
void add(int &x,int y){
	x = x + y < mod ? x + y : x + y - mod;
}
signed main(){
	cin >> n >> k;
	for(rei i = 1;i <= k;++i) scanf("%lld%lld",&l[i],&r[i]);
	dp[1] = sum[1] = 1;
	for(rei i = 2;i <= n;++i){
		for(rei j = 1;j <= k;++j){
			add(dp[i],(sum[max(i - l[j],(long long)0)] - sum[max(i - r[j],(long long)1) - 1] + mod) % mod);
		} add(sum[i],sum[i - 1]),add(sum[i],dp[i]);
	} cout << dp[n] << endl; return 0;
}