#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 998244353;
const ll INF = 1e18;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(v) v.begin(),v.end()

int main(){
	int n, k; cin >> n >> k;
	VI l(k), r(k);
	REP(i,n) cin >> l[i] >> r[i];
	VI dp(n); dp[0]=1; dp[1]=-1;
	ll now=0;
	for(int i=0;i<n;i++){
		now=(now+dp[i])%MOD;
		REP(j,k){
			int lp=i+l[j], rp=i+r[j]+1;
			if(lp<n)
				dp[lp]=(dp[lp]+now)%MOD;
			if(rp<n)
				dp[rp]=(dp[rp]-now+MOD)%MOD;
		}
	}
	cout << now << endl;
	return 0;
}