#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
long dp[200007]={},sumdp[200007]={},mod = 998244353;
int main(){
    int n,k;
    cin >> n >> k;
    dp[0] = 1;
    sumdp[0] = 0;
    sumdp[1] = 1;
    int l[k],r[k];
    rep(i,k) cin >> l[i] >> r[i];
    for(int i=1;i<n;i++){
        rep(j,k){
            int x = i-l[j],y = max(i-r[j],0);
            if(x<y) continue;
            long k = sumdp[x+1]-sumdp[y];
            if(k<0) k += mod;
            dp[i] += k;
            dp[i] %= mod;
        }
        sumdp[i+1] = sumdp[i] + dp[i];
        sumdp[i+1] %= mod;
    }
    cout << dp[n-1] << endl;
}