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

int main() {
    int n, k; cin >> n >> k;
    int M = 998244353;
    pair<int,int> segs[k];

    for(int i=0; i<k; i++) {
        cin >> segs[i].first >> segs[i].second;
    }
    sort(segs, segs+k);

    vector<int> pres;
    for (auto seg: segs)
        for (int j=seg.first; j<=seg.second; j++)
            pres.push_back(j);

    int dp[n+1] = {0};
    dp[n] = 1;
    for (int i = n; i > 0; i--) {
        for (int p : pres) {
            if (i <= p) break;
            dp[i-p] = (dp[i-p] + dp[i]) % M;
        }
    }

    cout << dp[1] << '\n';
}
