#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll N = 2e5 + 10, MOD = 998244353;
ll dp[N], n, k, l[N], r[N];
int f(ll l, ll r) {
    if(l > r || r <= 0) return 0;
    l = max(l, 1ll);
    r = min(r, n);
    return (MOD + dp[r] - dp[l - 1]) % MOD;
}
int main() {
    cin >> n >> k;
    for(int i = 1; i <= k; ++i) {
        cin >> l[i] >> r[i];
    }
    dp[1] = 1;
    for(int i = 2; i <= n; ++i) {
        dp[i] = dp[i - 1];
        for(int j = 1; j <= k; ++j) {
            dp[i] = (dp[i] + f(i - r[j], i - l[j])) % MOD;
        }
    }
    cout << (MOD + dp[n] - dp[n - 1]) % MOD << endl;
}