#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define mod 998244353

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll k;
    cin>>k;
    set<ll> s;
    vector<pair<ll,ll>> v;
    for(ll i=0;i<k;i++)
    {
    	ll x1,x2;
    	cin>>x1>>x2;
    	v.push_back(make_pair(x1,x2));
    }
    ll pr[n+1]={0};
    pr[0]=0;
    pr[1]=1;
    ll dp[n+1]={0};
    dp[0]=0;
    dp[1]=1;
    for(ll i=2;i<=n;i++)
    {
    	for(auto u:v)
    	{
    		if(u.first<i)
    		{
    		
    	    dp[i]=dp[i]+pr[i-u.first];
    		ll v=min(u.second+1,i);
    		//cout<<v<<endl;
    		dp[i]=dp[i]-pr[i-v];
    		}
    	}
    	pr[i]=pr[i-1]+dp[i];
    	//cout<<dp[i]<<endl;
    }
    cout<<dp[n]%mod<<endl;
	return 0;
}