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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll mod = 998244353;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// head


ll add(ll a, ll b) {
    a %= mod;
    b %= mod;
    a += b;
    a %= mod;
    return a;
}

ll sub(ll a, ll b) {
    a -= b;
    if(a < 0) {
        a += mod;
    }
    return a;
}

void fix(int& a) {
    if(a < 0) {
        a += mod;
    }
    if(a >= mod) {
        a -= mod;
    }
}

const int nax = 2e5+2;
vll t(4*nax,0);
vll lazy(4*nax,0);
 
void build(vll& a, int v, int tl, int tr) {
    if(tl == tr) t[v] = a[tl];
    else {
        int tm = (tl + tr) / 2;
        build(a,v*2,tl,tm);
        build(a,v*2+1,tm+1,tr);
        t[v] = add(t[v * 2], t[v * 2 + 1]);
    }
}
 
void push(int v) {
    if(lazy[v] != 0) {
        t[v*2] = add(t[v*2], lazy[v]);
        lazy[v*2] = add(lazy[v*2], lazy[v]);
        t[v * 2 + 1] = add(t[v * 2 + 1], lazy[v]);
        lazy[v * 2 + 1] = add(lazy[v * 2 + 1], lazy[v]);
        lazy[v] = 0;
    }
}
 
void update(int v, int tl, int tr, int l, int r, ll val) {
    if(l > r) return;
    if(l == tl && r == tr) {
        lazy[v] = add(lazy[v], val);
        t[v] = add(t[v], val);
    } else {
        push(v);
        int tm = (tl + tr) / 2;
        update(v*2,tl,tm,l,min(r,tm),val);
        update(v*2+1,tm+1,tr,max(l,tm+1),r,val);
        t[v] = add(t[2 * v], t[v * 2 + 1]);
    }
}
 
ll sum(int v, int tl, int tr, int l, int r) {
    if(l > r) return 0;
    if(l <= tl && tr <= r) return t[v];
    push(v);
    int tm = (tl + tr) / 2;
    return add(sum(v*2,tl,tm,l,min(r,tm)), sum(v*2+1,tm+1,tr,max(l,tm+1),r));
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    // what are we finding ? 
    // -> how many ways we can get to N using only moves from S
    // from what cells can we move d steps?
    // figure out how many ways we get to cell i, then for each possible moves, we go backwards from N
    // from what cells can we 
    int n, k;
    cin >> n >> k;
    vector<pair<int, int>> segments(k);
    vector<ll> dp(n + 1);
    dp[1] = 1;
    build(dp, 1, 0, n);
    for(int i = 0; i < k; i++) {
        int l, r;
        cin >> l >> r;
        segments[i] = mp(l, r);
    }
    for(int i = 1; i < n; i++) {
        //vector<int> prefix_sums = dp;
        ll val = sum(1, 0, n, i, i);
        //cout << "curr val : " << val << endl << flush;
        //cout << "curr dp val : " << dp[i] << endl << flush;
        //assert(val == dp[i]);
        for(int j = 0; j < k; j++) {
            int lower = segments[j].first;
            int higher = min(n - i, segments[j].second);
            if(i + lower <= n)
                update(1, 0, n, i + lower, i + higher, val);
            //segtree.update(1, 0, n, i + higher, val);
            //cout << higher << endl;
            //add(prefix_sums[i + lower], dp[i]);
            //sub(prefix_sums[i + higher + 1], dp[i]);
            //prefix_sums[i + lower] += dp[i];
            //prefix_sums[i + higher + 1] -= dp[i];
            //add(dp[i + lower], dp[i]);
            //sub(dp[i + higher + 1], dp[i]);
            /*for(int l = segments[j].first; l <= segments[j].second; l++) { // we need to add dp[i] to the segment that this lies
                if(i + l <= n) {
                    //cout << l << " ";
                    dp[i + l] += dp[i];
                    dp[i + l] %= mod;
                }
            }*/
            //cout << "Should be : " << higher;
            //cout << endl;



            // lower bound is i + lower -> max value where i + l <= n, l <= n - i , therefore, 
        }
        /*for(int j = 0; j < n; j++) {
            add(dp[j + 1], dp[j]);
        }*/

        /*for(int j = 0; j <= n; j++) {
            add(prefix_sums[j + 1], prefix_sums[j]);
            fix(prefix_sums[j]);
        }
        dp = prefix_sums;*/
    }

    //cout << dp[n] << endl;
    cout << sum(1, 0, n, n, n) % mod << endl;

    return 0;
}


Measured memory_bytes: 17232