#include<bits/stdc++.h>
using namespace std;


using ll =long long;
const ll MOD = 998244353;

int main(){
    ll n,i,k,j;
    cin>>n>>k;
    ll dp[n+2] ={0};
    dp[1] = 0;
    ll arr[k][2];
    for(i=0;i<k;i++)cin>>arr[i][0]>>arr[i][1];
    for(i=0;i<k;i++){
        dp[min(n+1,1+arr[i][0])]++;
        dp[min(n+1,1+arr[i][1]+1)]--;
    }

    //for(i=1;i<=n+1;i++)cout<<dp[i]<<" ";
    //cout<<"\n";
    for(i=2;i<n;i++){
        //for(int q=1;q<=n+1;q++)cout<<dp[q]<<" ";
        //cout<<"\n";
        dp[i]+=dp[i-1];
        while(dp[i]<0)dp[i]+=MOD;
        dp[i]%=MOD;
        for(j=0;j<k;j++){
            dp[min(n+1,i+arr[j][0])]+=dp[i];
            dp[min(n+1,i+arr[j][1]+1)]-=dp[i];
        }
        //cout<<dp[i]<<"\n";
    }
    //for(i=1;i<=n+1;i++)cout<<dp[i]<<" ";
    dp[n]+=dp[n-1];
    cout<<(dp[n]%MOD);
}
