#include <iostream>
using namespace std;
#define fi first
#define se second
#define ll long long int
#define pb push_back
#define MOD 998244353
int main(){
    ll a, b;
    cin>>a>>b;
    pair <ll, ll> r[b];
    for (ll i=0; i<b; i++) cin>>r[i].fi>>r[i].se;
    ll diff[2*a+2], dp[a+1];
    for (ll i=0; i<=a+1; i++) diff[i]=0;
    for (ll i=0; i<=a; i++) dp[i]=0;
    dp[1]=1;
    for (ll i=1; i<=a; i++){
        diff[i]+=diff[i-1];
        dp[i]+=diff[i];
        dp[i]%=MOD;
        for (ll j=0; j<b; j++) diff[i+r[j].fi]+=dp[i], diff[i+r[j].fi]%=MOD, diff[i+r[j].se+1]-=dp[i];
    }
    cout<<dp[a]<<endl;
}