#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

const ULL M = 998244353;

int main() {
    int N, K; cin >> N >> K;
    int I[10][2]; rep(i, K) rep(j, 2) cin >> I[i][j];
    ULL dp[400001] = {}; dp[0] = 1; dp[1] = M - 1;
    rep(i, N - 1) {
        rep(k, K) {
            dp[i + I[k][0]] += dp[i];
            dp[i + I[k][1] + 1] += M - dp[i];
        }
        dp[i + 1] += dp[i];
        dp[i + 1] %= M;
    }
    cout << dp[N - 1] << endl;
    return 0;
}