/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 200010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

ll MOD = 998244353;
int n, k, f[MAXN];
vector<II> a;
ll t[MAXN * 8], lazy[MAXN * 8];

ll binPowMod(ll a, ll b) {
    a %= MOD;
    ll res = 1;
    while (b > 0) {
        if (b & 1LL) res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1LL;
    }
    return res;
}

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

ll sub(ll a, ll b) {
    return (a - b + MOD) % MOD;
}

ll mul(ll a, ll b) {
    return a * b % MOD;
}

void build(int k, int l, int r) {
    if (l > r) return;
    if (l == r) {
        t[k] = (l == 1 ? 1 : 0);
        return;
    }
    int m = (l + r) >> 1;
    build(k*2, l, m);
    build(k*2+1, m+1, r);
    t[k] = max(t[k*2], t[k*2+1]);
}

void lazyUpdate(int k, int l, int r) {
    if (l > r) return;
    if (lazy[k] == 0) return;
    t[k] = add(t[k], lazy[k]);
    if (l < r) {
        lazy[k*2] = add(lazy[k*2], lazy[k]);
        lazy[k*2+1] = add(lazy[k*2+1], lazy[k]);
    }
    lazy[k] = 0;
}

ll get(int k, int l, int r, int u) {
    lazyUpdate(k, l, r);
    if (l > r || r < u || u < l) return -1e18;
    if (l == r) return t[k];
    int m = (l + r) >> 1;
    if (u <= m) return get(k*2, l, m, u);
    return get(k*2+1, m+1, r, u);
}

void update(int k, int l, int r, int u, int v, ll val) {
    lazyUpdate(k, l, r);
    if (l > r || r < u || v < l) return;
    if (u <= l && r <= v) {
        lazy[k] = add(lazy[k], val);
        lazyUpdate(k, l, r);
        return;
    }
    int m = (l + r) >> 1;
    update(k*2, l, m, u, v, val);
    update(k*2+1, m+1, r, u, v, val);
    t[k] = max(t[k*2], t[k*2+1]);
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> k;
    FOR(i,1,k) {
        int l, r;
        cin >> l >> r;
        f[l]++;
        f[r+1]--;
    }
    FOR(i,1,n+1) f[i] += f[i-1];
    int cnt = 0, fi = 0;
    FOR(i,1,n+1)
        if (f[i]) {
            cnt++;
            if (cnt == 1) fi = i;
        } else {
            if (cnt == 0) continue;
            a.push_back(II(fi, i-1));
            cnt = 0;
        }
    build(1,1,n);
    FOR(i,1,n) {
        ll x = get(1,1,n,i);
        // cout << i << ' ' << x << endl;
        for (II p : a) {
            int L = i + p.FI, R = i + p.SE;
            if (L > n) continue;
            R = min(R, n);
            // cout << L << ' ' << R << endl;
            update(1,1,n,L,R,x);
        }
        // cout << "\n";
    }
    cout << get(1,1,n,n);
    return 0;
}


Measured memory_bytes: 12548