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

const ll MOD = 998244353;
template<ll MOD> struct ModInt {
    ll value;
    ModInt() : value(0) {}
    ModInt(const ll& v) : value(v % MOD) {
        if ( value < 0 ) value += MOD;
    }
    ModInt<MOD>& operator=(const ModInt& o) {
        value = o.value;
        return *this;
    }
    inline bool operator==(const ModInt& o) {
        return value == o.value;
    }
    inline bool operator!=(const ModInt& o) {
        return value != o.value;
    }
    ModInt<MOD>& operator+=(const ModInt& o) {
        value += o.value;
        if ( value >= MOD ) value -= MOD;
        return *this;
    }
    ModInt<MOD>& operator-=(const ModInt& o) {
        value += MOD - o.value;
        if (value >= MOD ) value -= MOD;
        return *this;
    }
    ModInt<MOD>& operator*=(const ModInt& o) {
        value *= o.value;
        value %= MOD;
        return *this;
    }
    ModInt<MOD>& operator/=(const ModInt& o) {
        value *= inverse(o.value);
        value %= MOD;
        return *this;
    }
    ModInt<MOD> operator-() {
        return ModInt<MOD>(-value);
    }
    ModInt<MOD> operator+(const ModInt& o) {
        ModInt<MOD> r(*this);
        r += o;
        return r;
    }
    ModInt<MOD> operator-(const ModInt& o) {
        ModInt<MOD> r(*this);
        r -= o;
        return r;
    }
    ModInt<MOD> operator*(const ModInt& o) {
        ModInt<MOD> r(*this);
        r *= o;
        return r;
    }
    ModInt<MOD> operator/(const ModInt& o) {
        ModInt<MOD> r(*this);
        r /= o;
        return r;
    }
    ModInt<MOD> pow(ll n) {
        ModInt<MOD> t(*this), r = 1;
        while ( n > 0 ) {
            if ( n & 1 ) r *= t;
            t *= t;
            n >>= 1;
        }
        return r;
    }
private:
    ll inverse(ll a) {
        ModInt<MOD> t(a);
        return t.pow(MOD - 2).value;
    }
};

template<typename T> struct BIT {
    int mxn;
    vector<T> data;
    const bool zi;
    const T un;
    BIT<T>(int max_n, bool zero_indexed = false, T unit = T(0)) : mxn(max_n), zi(zero_indexed), un(unit) {
        if ( zi ) mxn++;
        data.assign(mxn + 1, unit);
    }
    void add(int i, T x) {
        if ( zi ) i++;
        assert( i > 0 );
        while ( i <= mxn ) {
            data[i] += x;
            i += i & -i;
        }
    }
    T sum(int i) {
        if ( zi ) i++;
        assert( i > 0 );
        T s = un;
        while ( i > 0 ) {
            s += data[i];
            i -= i & -i;
        }
        return s;
    }
    vector<T> get_sum_list(int l, int r) {
        vector<T> a;
        for ( int i = l; i <= r; i++ ) {
            a.push_back(sum(i));
        }
        return a;
    }
};

using mint = ModInt<MOD>;

ll solve() {
    ll N, K, l, r;
    cin >> N >> K;
    vector<ll> L(K), R(K);
    for ( int i = 0; i < K; i++ ) {
        cin >> L[i] >> R[i];
    }
    vector<int> u(N+1);
    for ( int i = 0; i < K; i++ ) {
        for ( int j = L[i]; j <= R[i]; j++ ) {
            u[j] = 1;
        }
    }
    BIT<mint> dp(N+2, true);
    dp.add(1,1);
    for ( int i = 2; i <= N; i++ ) {
        mint x = 0;
        for ( int j = 0; j < K; j++ ) {
            l = i - R[j], r = i - L[j];
            if ( l < 0 ) l = 0;
            if ( r < 0 ) r = 0;
            x += dp.sum(r);
            if ( l > 0 ) x -= dp.sum(l-1);
        }
        dp.add(i, x);
    }
    mint ans = dp.sum(N) - dp.sum(N-1) ;
    return ans.value;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 5636