#include<iostream>
#include<vector>
#include<atcoder/all>
#define mod 998244352
#define ll long long

using namespace std;
using namespace atcoder;

int main(){
    ll n, k;
    cin >> n >> k;
    ll l[k], r[k];
    for (int i = 0; i < k;i++){
        cin >> l[i] >> r[i];
    }

    vector<ll> dp(n + 1);
    vector<ll> dpsum(n + 1);
    dp[1] = 1;
    dpsum[1] = 1;

    for (int i = 2; i <= n;i++){
        for (int j = 0; j < k;j++){
            int li = (i - r[j]) % mod;
            int ri = (i - l[j]) % mod;
            if(ri < 0) continue;
            li = max(li, 1);
            dp[i] += (dpsum[ri] - dpsum[li - 1]) % mod;
            dp[i] %= mod;
        }
        dpsum[i] = (dpsum[i-1] + dp[i]) % mod;
        dpsum[i] %= mod;
    }
    cout << dp[n] << endl;
    return 0;
}