#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=998244353;
const ll z=0;
ll n,k;
P s[15];
ll ans[200005];
int main(void){
    cin>>n>>k;
    for(int i=0;i<k;i++){
        cin>>s[i].first>>s[i].second;
    }
    sort(s,s+k);
    ans[1]=1;
    for(ll i=2;i<=n;i++){
        for(int j=0;j<k;j++){
            ans[i]=(ans[i]+ans[max(i-s[j].first,z)]-ans[max(i-s[j].second-1,z)])%MOD;
        }
        ans[i]=(ans[i]+ans[i-1])%MOD;
        //cout<<ans[i]-ans[i-1]<<endl;
    }
    ll ANS=(ans[n]-ans[n-1])%MOD;
    if(ANS<0) ANS+=MOD;
    cout<<ANS<<endl;
    
}
