#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
const ll mod=998244353;
int main(void){
    ll n,k;
    cin>>n>>k;
    vector<pair<ll,ll>>p(k);
    rep(0,i,n){
        cin>>p[i].first>>p[i].second;
    }
    ll dp[n+1],pre[n+1];
    rep(0,i,n+1){
        dp[i]=pre[i]=0;
    }
    pre[1]=1,dp[1]=1;
    rep(2,i,n+1){
        rep(0,j,k){
            ll l=p[j].first,r=p[j].second;
            if(i-l<=0)continue;
            dp[i]=(dp[i]+pre[i-l]-pre[max((ll)0,i-r-1)]+mod)%mod;
        }
        pre[i]=(dp[i]+pre[i-1])%mod;
        //cout<<dp[i]<<endl;
    }
    cout<<dp[n];
}