#ifdef Dhiraj
    #include "D:/dhiraj/Programming/debug.h"
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 11
    #define cerr if(0) cerr
#endif

// Macro --------------------------------------------------------------------

#define ll                  long long int
#define FOR(i, a, b, s)     for(ll i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define FOR1(b)             FOR(i, 0, b, 1)
#define FOR2(i, b)          FOR(i, 0, b, 1)
#define FOR3(i, a, b)       FOR(i, a, b, (a) <= (b) ? 1 :-1)
#define FOR4(i, a, b, s)    FOR(i, a, b, s)
#define GET5(a, b, c, d, e, ...) e
#define FORC(...)           GET5(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)
#define loop(...)           FORC(__VA_ARGS__)(__VA_ARGS__)
#define all(x)              (x).begin(), (x).end()
#define rall(x)             (x).rbegin(), (x).rend()
#define endl                '\n'

// Template -----------------------------------------------------------------

// multiple input
template <typename... T> 
inline void inp(T&... args) {
    ((cin >> args), ...);
}
// scan vector
template <typename T> 
inline istream& operator >>(istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// scan pair
template <typename T, typename U> 
inline istream& operator >>(istream &in, pair<T, U> &a) {
    in >> a.first >> a.second; 
    return in;
}

// Solve --------------------------------------------------------------------

const ll Mod = 998244353;
inline ll md(ll x, ll M = Mod)
{
    x %= M;
    return ((x < 0) ? (x + M) : x);
}


// Note : 1 based index

inline ll lsb(ll x) { // Least Significant Bit
    return (x & -x);
}

struct Fenwick
{
    ll n;
    vector<ll> bit;

    Fenwick(ll _n = 1e5)
    {
        n = _n;
        bit.assign(n + 5, 0);
    }
    void add(ll ind, ll val) // arr[ind] += val;
    {
        for(ll i = ind; i <= n; i += lsb(i)) {
            bit[i] += val;
        }
    }
    void add(ll l, ll r, ll val)
    {
        add(l, val);
        add(r + 1, -val);
    }
    ll sum(ll ind)
    {
        ll ans = 0;
        for(ll i = ind; i > 0; i -= lsb(i)) {
            ans = md(ans + bit[i]);
        }
        return ans;
    }
    ll sum(ll l, ll r) {
        return md(sum(r) - sum(l - 1));
    }
    friend void deprint(Fenwick &f)
    {
        cerr << "BIT(" << f.n << ") : ";
        for (ll i = 1; i <= f.n; i++) {
            cerr << f.sum(i, i) << " ";
        }
    }
};

void solve(int &T)
{
    ll n, k;
    cin >> n >> k;

    set<ll> a;
    loop(j, k)
    {
        ll l, r;
        cin >> l >> r;
        loop(i, l, r + 1) {
            a.insert(i);
        }
    }
    a.insert(n + 2);
    d(a);

    vector<pair<ll, ll>> b;
    ll first = *a.begin(), last = *a.begin();

    for(ll x : a) {
        if(x != last) {
            b.push_back({first, last});
            first = last = x;
        }
        last++;
    }
    d(b);

    Fenwick dp(2 * n + 5);
    loop(i, 1, n + 1)
    {
        for(auto &r : b) {
            dp.add(i + r.first, i + r.second - 1, (i == 1) + (dp.sum(i)));
        }
    }
    cout << dp.sum(n) << endl;
}

// Main ---------------------------------------------------------------------

int main()
{
    #ifdef Dhiraj
        freopen("D:/dhiraj/Programming/i1.txt", "r", stdin);
        freopen("D:/dhiraj/Programming/o1.txt", "w", stdout);
        freopen("D:/dhiraj/Programming/e1.txt", "w", stderr);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    for(int i = 1; i <= t; i++) {
        cerr << "Case #" << i << "\n";
        solve(i);
    }
    return 0;
}

Measured memory_bytes: 15536