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

int main() {
    cout << fixed << setprecision(0);
    int64_t N, K;
    cin >> N >> K;
    vector<int64_t> L(K), R(K);
    for(int i = 0; i < K; i++) {
        cin >> L[i] >> R[i];
    }

    const int64_t MOD = 998244353;
    vector<int64_t> ans(N), sm(N);
    ans[0] = 1;
    sm[0] = 1;

    for(int64_t i = 1; i < N; i++) {
        for(int64_t j = 0; j < K; j++) {
            if(i - L[j] < 0)
                continue;
            int64_t s = max(0LL, i - R[j]);
            int64_t g = min(i - 1, i - L[j]);
            ans[i] =
                (sm[g] + MOD - (s - 1 >= 0 ? sm[s - 1] : 0) + ans[i]) % MOD;
        }
        sm[i] = (sm[i - 1] + ans[i]) % MOD;
    }

    cout << ans[N - 1] << endl;

    return 0;
}