#include <bits/stdc++.h>

#ifndef ONLINE_JUDGE
#include "/home/datbeohbbh/cptemplates/debug.h"
using namespace DEBUG;
#endif

using namespace std;

template <class T,class U>
void maximize(T &lhs,U rhs){
    if(lhs < rhs)lhs = rhs;
}
template <class T,class U>
void minimize(T &lhs,U rhs){
    if(lhs > rhs)lhs = rhs;
}
template <class T>
T tabs(T x){
    return (x < (T)0 ? -x : x);
}

#define len(c) (int)((c).size())
#define llong int64_t
#define MASK(i) ((1LL) << (i))
#define BIT(x,i) (((x) >> (i)) & 1)
#define file_name "test"    /// FILE NAME HERE!!!

/* ================================= END OF TEMPLATE ================================= */

namespace MODULAR {
    template< class T, T MOD >
    class Modular {
    private :
        T value;
    public:
        using modular = Modular < T , MOD >;
        Modular < T, MOD > () : value(0){}
        explicit Modular< T, MOD > (const T &initValue) : value(initValue % MOD){ if(value < 0){ value += MOD; } }
        modular& operator = (const modular &other) { value = other.value; return *this; }
        bool operator <  (const modular &other) const { return value < other.value; }
        bool operator >  (const modular &other) const { return value > other.value; }
        bool operator == (const modular &other) const { return !(*this < other) && !(*this > other);}
        bool operator != (const modular &other) const { return !(*this == other); }
        bool operator <= (const modular &other) const { return !(*this > other); }
        bool operator >= (const modular &other) const { return !(*this < other); }
        friend ostream& operator << (ostream &out, const modular &other) { return out << other.value; }
        friend istream& operator >> (istream &inp, modular &other) { return inp >> other.value; }
        modular& operator += (const modular &x) { value = (value % MOD + x.value % MOD + MOD) % MOD; return *this; }
        modular& operator -= (const modular &x) { value = (value % MOD - x.value % MOD + MOD) % MOD; return *this; }
        modular operator - () const { return modular(0) - *this; }
        modular& operator ++ () { return (*this += modular(1)); }
        modular& operator -- () { return (*this -= modular(1)); }
        T multiply(T lhs,T rhs);
        modular& operator *= (const modular &x) { value = multiply(value,x.value); return *this; }
        modular operator * (const modular &x){ return (modular(*this) *= x); }
        modular operator + (const modular &x) { return (modular(*this) += x); }
        modular operator - (const modular &x) { return (modular(*this) -= x); }
        T multiply(T lhs,T rhs) const {
            int count_bit_mod = __builtin_popcountll(MOD);
            if((count_bit_mod << 1) < 64){
                return ( (lhs % MOD) * (rhs % MOD) ) % MOD;
            } else {
                T ret = 0;
                for(; rhs > 0; rhs >>= 1){
                    if(rhs % 2){
                        ret += lhs;
                        if(ret >= MOD)ret -= MOD;
                    }
                    lhs <<= 1;
                    if(lhs >= MOD)lhs -= MOD;
                }
                return ret;
            }
        }
        T powerValue(T h) const {
            T ret = (T)1;
            T tmp_value = value;
            for(; h > (T)0 ;h /= (T)2){
                if(h % (T)2)ret = multiply(ret,tmp_value);
                tmp_value = multiply(tmp_value,tmp_value);
            }
            return ret;
        }
        T inverseValue() const { return powerValue(MOD - 2); }
        modular toPower(T h) const { return modular(powerValue(h)); }
        modular toInverse() const { return modular(inverseValue()); }
        T getValue() const { return value; }
    };
}
using namespace MODULAR;
using ModInt = int64_t;
const ModInt Base = (ModInt)998244353;
using Mint = Modular<ModInt, Base>;

// Note: 'ModInt Base' must be prime number.

namespace Task{

    class FenwickTree{
        public:
            vector < Mint > tree;
            int sizeTree = 0;
            FenwickTree(int init_sizeTree):sizeTree(init_sizeTree){
                tree.resize(sizeTree + 2,Mint(0));
            }
            
            void update(int node,Mint val){
                for(;node <= sizeTree;node |= (node + 1)){
                    tree[node] += val;
                }
            }
            
            Mint rsq(int node){
                Mint ret = Mint(0);
                for(;node >= 0;node = (node & (node + 1)) - 1){
                    ret += tree[node];
                }
                return ret;
            }
            
            Mint rsq(int l,int r){
                return rsq(r) - rsq(l - 1);
            }
    };
    FenwickTree *fwt;
    
    void solve(){
        int n,k;
        cin>>n>>k;
        vector < int > l(k + 2,0);
        vector < int > r(k + 2,0);
        for(int i = 1;i <= k;++i){
            cin>>l[i]>>r[i];
        }
        vector < Mint > f(n + 2,Mint(0));
        f[1] = Mint(1);
        fwt = new FenwickTree(n);
        fwt -> update(1,f[1]);
        for(int i = 2;i <= n;++i){
            for(int j = 1;j <= k;++j){
                if(i >= l[j]){
                    f[i] += fwt -> rsq(i - min(i,r[j]),i - l[j]);
                }
            }
            fwt -> update(i,f[i]);
        }
        cout<<f[n]<<'\n';
    }
}

int main(int argc, char** argv){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    Task::solve();
}



Measured memory_bytes: 6304