#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
using LL = long long;
using P = pair<int,int>;
const LL mod = 998244353;

int main(){
	LL N, K;
	cin >> N >> K;
	vector<LL> L(K), R(K);
	rep(i,K) cin >> L[i] >> R[i];
	vector<LL> dp(N+1), num(K), sum(N+1);
	dp[1]=1, sum[1]=1;
	for(int i=2; i<=N; i++){
		rep(j,K){
			if(R[j]<i){
				num[j]+=dp[i-L[j]];
				num[j]-=dp[i-R[j]-1];
				dp[i]+=num[j];
			}
			else if(L[j]<i){
				num[j]+=dp[i-L[j]];
				dp[i]+=sum[i-L[j]];
			}
			dp[i]%=mod;
			sum[i]=(sum[i-1]+dp[i]);
			sum[i]%=mod;
		}
	}
	LL ans=dp[N];
	while(ans<0) ans+=mod;
	cout << ans << endl;

	return 0;
}