#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vl=vector<ll>;
#define MOD 998244353
int main() {
    ll N; cin>>N;
    ll K; cin>>K;
    vl L(K),R(K);
    for (int i = 0; i < K; i++){
        cin>>L[i]>>R[i];
    }
    vl dp(N+1,0),sum(N+1,0);
    dp[1]=1;sum[1]=1;
    for (int i = 2; i < N+1; i++){
        for (int j = 0; j < K; j++){
            if(i-L[j]<1)continue;
            if(i-R[j]<1)dp[i]=(dp[i]+sum[i-L[j]])%MOD;
            else dp[i]=((dp[i]+sum[i-L[j]]-sum[i-R[j]-1])%MOD+MOD)%MOD;
        }
        sum[i]=(sum[i-1]+dp[i])%MOD;
    }
    cout<<dp[N]<<endl;
}