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

using ll = long long;

int main() {
    const ll mod = 998244353;
    int n, k;
    cin >> n >> k;
    vector<pair<int, int>> kukan(k);
    for (int i = 0; i < k; ++i) {
        cin >> kukan[i].first >> kukan[i].second;
    }
    vector<ll> dp(2*n+1, 0);
    vector<ll> ssum(k, 0);
    dp[n] = 1;
    for (int i = n+1; i < 2*n+1; ++i) {
        ll sum = 0;
        for (int j = 0; j < k; ++j) {
            ssum[j] = (ssum[j] - dp[i-kukan[j].second-1] + dp[i-kukan[j].first] + mod) % mod;
            (sum += ssum[j]) %= mod;
        }
        (dp[i] += sum) %= mod;
    }
    cout << dp[2*n-1] << endl;
}