#include <iostream>
#include <vector>
using namespace std;
const int MOD = 998244353;
int main(){
    int N, K;
    cin >> N >> K;
    vector<int> L(K), R(K);
    for(int i = 0; i < K; i++) cin >> L[i] >> R[i];
    vector<long long> dp(N + 1, 0);
    vector<long long> sum(N + 1, 0);
    dp[1] = 1;
    sum[1] = 1;
    for(int i = 2; i < N + 1; i++){
        for(int j = 0; j < K; j++){
            dp[i] += sum[max(0, i - L[j])] - sum[max(0, i - R[j] - 1)];
            dp[i] %= MOD;
        }
        sum[i] += sum[i - 1] + dp[i];
        sum[i] %= MOD;
    }
    cout << (dp[N] + MOD) % MOD << endl;
}