#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const ll mod = 998244353;
const ll maxn = 2e5+10;

struct tnode{
    ll w,l,r,siz,alazy;
    ll sq,mlazy=1;
}tn[maxn<<2];

ll n,m;

ll wt[maxn];


void pushup(ll u){
    tn[u].w = (tn[u<<1].w + tn[u<<1|1].w) % mod;
    tn[u].sq = (tn[u<<1].sq + tn[u<<1|1].sq) % mod;
}

void build(ll u,ll l,ll r){
    tn[u].l = l;
    tn[u].r = r;
    tn[u].siz = r - l + 1;
    if(l == r){
        tn[u].w = wt[l];
        tn[u].sq = wt[l] * wt[l];
        return ;
    }
    ll mid = (l+r) >> 1;
    build(u<<1 , l , mid);
    build(u<<1|1 , mid+1 , r);
    pushup(u);
}

void pushdown(ll u){
    if(tn[u].alazy != 0 or tn[u].mlazy != 1){
        tn[u<<1].sq = ((tn[u<<1].sq + 2LL * tn[u<<1].w * tn[u].alazy % mod) % mod + tn[u].alazy * tn[u].alazy % mod * tn[u<<1].siz % mod) % mod;
        tn[u<<1|1].sq = ((tn[u<<1|1].sq + 2LL * tn[u<<1|1].w * tn[u].alazy % mod) % mod + tn[u].alazy * tn[u].alazy % mod * tn[u<<1|1].siz % mod) % mod;

        tn[u<<1].w =  (tn[u<<1].w * tn[u].mlazy  % mod + tn[u<<1].siz * tn[u].alazy % mod) % mod;
        tn[u<<1|1].w = (tn[u<<1|1].w * tn[u].mlazy  % mod + tn[u<<1|1].siz * tn[u].alazy % mod) % mod;


        tn[u<<1].alazy = (tn[u<<1].alazy * tn[u].mlazy % mod + tn[u].alazy) % mod;
        tn[u<<1|1].alazy = (tn[u<<1|1].alazy * tn[u].mlazy % mod + tn[u].alazy) % mod;

        tn[u<<1].mlazy = (tn[u<<1].mlazy * tn[u].mlazy) % mod;
        tn[u<<1|1].mlazy = (tn[u<<1|1].mlazy * tn[u].mlazy) % mod;


        tn[u].alazy = 0;
        tn[u].mlazy = 1;
    }
}

ll query(ll u,ll l,ll r,ll t){
    if(l<=tn[u].l and r>=tn[u].r) {
        if(t == 1) return tn[u].w;
        if(t == 2) return tn[u].sq;
    }

    ll ans = 0;
    pushdown(u);
    ll mid = (tn[u].l + tn[u].r) >> 1;
    if(l<=mid) ans = (ans + query(u<<1 , l , r , t)) % mod;
    if(r>mid) ans = (ans + query(u<<1|1 , l , r , t)) % mod;
    return ans;
}


void update(ll u,ll l,ll r,ll wa,ll wm){
    if(l<=tn[u].l and r>=tn[u].r){
        tn[u].sq = ((tn[u].sq + 2LL * tn[u].w * wa % mod) % mod + wa * wa % mod * tn[u].siz % mod) % mod;
        tn[u].w = (tn[u].w * wm % mod + tn[u].siz * wa % mod) % mod;

        tn[u].alazy = (tn[u].alazy * wm % mod + wa) % mod;
        tn[u].mlazy = (tn[u].mlazy * wm) % mod;

        return ;
    }
    pushdown(u);
    ll mid = (tn[u].l + tn[u].r) >> 1;
    if(l<=mid) update(u<<1, l , r , wa , wm);
    if(r>mid) update(u<<1|1, l , r , wa , wm);
    pushup(u);
}


int main() {
#ifdef LOCAL
    freopen("in1.txt", "r", stdin);
    freopen("out1.txt", "w", stdout);
#endif

    ll k;
    cin >> n >> k;
    wt[1] = 1;
    build(1, 1, n);

    vector<pair<ll, ll>> vt;
    for(int i = 0; i < k; ++i){
        ll u, v;
        cin >> u >> v;
        vt.emplace_back(u, v);
    }
    sort(vt.begin(), vt.end());
    for(ll i = 1; i < n; ++i){
        for(auto j : vt){
            if(i + j.second > n){
                if(i + j.first <= n){
                    update(1, i + j.first, n, query(1, i, i, 1) % mod, 1);
                }
                break;
            }
            else{
                update(1, i + j.first, i + j.second, query(1, i, i, 1) % mod, 1);
            }
        }
    }
    cout <<  query(1, n, n, 1) << endl;
    return 0;
}

Measured memory_bytes: 47396