#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

#define M 998244353

int main(){
	int n, k;
	cin>>n>>k;
	vector<int> l(k), r(k);
	rep(i, k) cin>>l[i]>>r[i];

	vector<int> dp(n), sdp(n);
	dp[0]=sdp[0]=1;
	for(int i=1; i<n; i++){
		rep(j, k){
			int s=i-r[j];
			int t=i-l[j];
			if(t<0) continue;
			int sdps= (s<=0)?0:sdp[s-1];
			dp[i]=((ll)dp[i] + sdp[t] - sdps +M)%M;
		}
		sdp[i]=((ll)sdp[i-1]+dp[i])%M;
	}

	cout<<dp[n-1]<<endl;
	return 0;
}
