#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD =998244353;
int main() {
    ll n,k;
    cin >> n >> k;
    vector<ll>l(k),r(k);
    for(ll i=0;i<k;i++) cin >> l[i] >> r[i];
    vector<ll>dp(2e5+20,0);
    vector<ll>sum(2e5+20,0);
    sum[1]=1;
    dp[1]=1;
    for(ll i=2;i<=n;i++){
        for(ll j=0;j<k;j++){
            ll li=i-r[j];
            ll ri=i-l[j];
            if(ri<0) continue;
            li=max(li,(ll)1);
            dp[i]+=(sum[ri]-sum[li-1]+MOD);
            dp[i]%=MOD;
        }
        sum[i]=sum[i-1]+dp[i];
        sum[i]%=MOD;
    }
    cout << dp[n] << endl;
}