#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10,mod=998244353;
int n,k,dp[N];
struct node{
    int l,r;
}e[11];
int main(){
    scanf("%d%d",&n,&k);
    dp[1]=1;
    for(int j=1;j<=k;++j){
        scanf("%d%d",&e[j].l,&e[j].r);
    }
    for(int i=2;i<=n;++i){
        dp[i]=dp[i-1];
        for(int j=1;j<=k;++j){
            int nr=i-e[j].l,nl=i-e[j].r;
            if(nr<1)continue;
            nl=max(nl,1);
            dp[i]=(dp[i]+dp[nr])%mod;
            dp[i]=(dp[i]-dp[nl-1])%mod;
            dp[i]=(dp[i]+mod)%mod;
        }
    }
    ll ans=(dp[n]-dp[n-1]+mod)%mod;
    printf("%lld\n",ans);
    return 0;
}
