#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n,k;
	cin>>n>>k;
	vector<pair<int,int>>s;
	vector<int>dp(2*n+5);

	for(int i=0;i<k;i++){
		int l,r;
		cin>>l>>r;
		s.push_back({l,r});
	}
	
	/*
	for(int j:s){
		cout<<j<<' ';
	}
	cout<<'\n';
	*/
	dp[1]=1;
	for(int i=1;i<=n;i++){
		dp[i]=(dp[i-1]+dp[i])%mod;
		for(int j=0;j<k;j++){
			int l = s[j].first,r=s[j].second;

			dp[i+l]=(dp[i]+dp[i+l])%mod;
			dp[i+r+1]=(dp[i+r+1]-dp[i])%mod;
		}
	}
	ll ans=(dp[n]-dp[n-1]+mod)%mod;
	cout<<ans<<'\n';
	
	return 0;
}