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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=998244353;

template<typename T> bool chmax(T &a,const T b){if(a < b){a=b; return true;} return false;}
template<typename T> bool chmin(T &a,const T b){if(a > b){a=b; return true;} return false;}


int main(){
    int N, K; cin >> N >> K;
    vi L(K), R(K);
    for(int i=0; i<K; i++){
        cin >> L[i] >> R[i];
    }
    vector<ll> dp(N+1, 0);
    for(int i=0; i<K; i++){
        dp[L[j]]=1;
        dp[R[j]]=1;
    }
    for(int i=1; i<=N; i++){
        dp[i]=dp[i-1];
        for(int j=0; j<K; j++){
            if(i-R[j] >= 0) dp[i]=(dp[i]+dp[i-R[j]])%MOD;
            if(i-L[j]-1 >= 0) dp[i]=(dp[i]-dp[i-L[j]-1])%MOD;
        }
    }

    if(dp[N] < 0) dp[N]+=MOD;
    cout << dp[N] << endl;
    return 0;
}