#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000



int main(){

	int N,K;
	cin>>N>>K;
	
	vector<int> L(K),R(K);
	rep(i,K)cin>>L[i]>>R[i];

	vector<mint> dp(N,0);
	dp[0] = 1;
	
	for(int i=1;i<N;i++){
		rep(j,K){
			if(i-L[j]>=0)dp[i] += dp[i-L[j]];
			if(i-R[j]-1>=0)dp[i] -= dp[i-R[j]-1];
		}
		dp[i] += dp[i-1];
	}

	
	cout<<(dp.back() - dp[N-2]).val()<<endl;

	return 0;
}

