#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 998244353;
int l[10], r[10];
// dp[i] = 範囲 [1, i] に到着する場合の数
ll dp[200001]={};
int main()
{
    ll n, k;
    cin >> n >> k;
    for(int i=0; i<k; ++i)cin >> l[i] >> r[i];
    dp[1]=1;
    for(int i=2; i<=n; ++i){
        dp[i] = dp[i-1];
        for(int j=0; j<k; ++j){
            int ll = max(1, i-r[j]);
            int rr = min(i-1, i-l[j]);
            if(ll<=rr){
                dp[i] += dp[rr] - dp[ll-1];
            }
        }
        dp[i] = (dp[i]%MOD + MOD)%MOD;
    }
    cout << (dp[n]-dp[n-1]+MOD)%MOD << endl;
    return 0;
}
