// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 998244353;
ll dp[N];
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, k;
    cin >> n >> k;
    vector<pair<ll, ll>> p(k);
    for (auto &[l, r] : p)
        cin >> l >> r;
    dp[1] = 1;
    for (ll i = 2; i <= n; i++)
    {
        for (auto [l, r] : p)
            dp[i] += dp[max(0L, i - l)] - dp[max(0L, i - r - 1)] + M, dp[i] %= M;
        if (i < n)
            dp[i] += dp[i - 1];
        dp[i] %= M;
    }
    cout << dp[n];
}