#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

const ll MOD = 998244353;

int main() {
    int n, k;
    cin >> n >> k;

    vector<vector<int>> ranges(k, vector<int>(2));
    for (int i = 0; i < k; i++)cin >> ranges[i][0] >> ranges[i][1];

    vector<ll> dp(n * 3);
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        for (auto range:ranges) {
            dp[i + range[0]] += dp[i], dp[i + range[0]] %= MOD;
            dp[i + range[1] + 1] += MOD - dp[i], dp[i + range[1]] %= MOD;
        }

        if (i > 0) dp[i + 1] += dp[i], dp[i + 1] %= MOD;
    }

    cout << dp[n - 1] << endl;
    return 0;
}
