#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi   = vector<int>;
using vll  = vector<ll>;
using vc   = vector<char>;
using vvll  = vector<vll>;
using vvi  = vector<vi>;
using vvc  = vector<vc>;
using vb   = vector<bool>;
using vvb  = vector<vb>;
using pii  = pair<int,int>;
using vpii = vector<pii>;
using posteriority_queue = priority_queue<int, vi, greater<int>>;

map<ll, ll> memo;
queue<int> empty;
ll constant = 998244353;

ll loop(posteriority_queue que, ll x) {
    ll ans = 0;
    posteriority_queue tmp_que = que;
    while(!tmp_que.empty()) {
        ll tmp = x - tmp_que.top();
        tmp_que.pop();
        if (tmp == 0) {
            ans++;
            break;
        }else if (tmp < 0) {
            break;
        } else if (memo.count(tmp)) {
            ans = (ans + memo.at(tmp)) % constant;
        } else {
            ans = (ans + loop(que, tmp)) % constant;
        }
    }
    swap(tmp_que, empty);
    memo[x] = ans % constant;
    return ans % constant;
}

int main() {
    ll N, K; cin >> N >> K;
    posteriority_queue que;
    for(ll i = 0; i < K; i++) {
        ll tmp1, tmp2; cin >> tmp1 >> tmp2;
        for(ll i = tmp1; i <= tmp2; i++) {
            que.push(i);
        }
    }
    cout << loop(que, N-1);

}
