#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

pair<int, int> S[16];

constexpr auto M = 998244353;
int D[500'000];
int reachable[500'005];

int main()
{
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < k; ++i) {
        int l, r;
        cin >> l >> r;
        S[i] = {l, r + 1};
    }
    sort(S, S + k);

    auto lvl = 0LL;
    D[1] = 1;
    D[2] = -1;
    reachable[1] = 1;
    reachable[2] = -1;
    auto reach = 0LL;
    for (auto pos = 1; pos <= n; ++pos) {
        reach += reachable[pos];
        if (reach <= 0) {
            continue;
        }
        lvl += M;
        lvl += D[pos];
        lvl %= M;

        for (auto i = 0; i < k; ++i) {
            auto l = pos + S[i].first;
            auto r = pos + S[i].second;
            reachable[l]++;
            reachable[r]--;
            D[l] += lvl;
            D[l] %= M;
            D[r] += M - lvl;
            D[r] %= M;
        }
    }
    cout << (reach <= 0 ? 0LL : lvl) << endl;
    return 0;
}
