#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double

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<ll> dp(N+1, 0), sum(N+1, 0);
    dp[1] = 1;
    sum[1] = 1;
    ll mod = 998244353;
    for (int i = 2; i <= N; i++) {
        for (int j = 0; j < K; j++) {
            int mr = max(i-L[j], 0), ml = max(i-R[j]-1, 0);
            dp[i] += sum[mr]-sum[ml]+mod;
        }
        dp[i] %= mod;
        sum[i] = (sum[i-1]+dp[i])%mod;
    }
    cout << dp[N]%mod << endl;
    return 0;
}
