#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
const int mod = 998244353;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<P> lr(k);
    vector<P> res;
    set<int> s;
    rep(i, k) {
        cin >> lr[i].first >> lr[i].second;
    }

    sort(lr.begin(), lr.end());

    res.push_back(lr[0]);
    for(int i=1; i<k; ++i) {
        P curr = lr[i];
        P last = res.back();
        if (curr.first <= last.second) {
            last.second = max(curr.second, last.second);
        } else {
            res.push_back(curr);
        }
    }

    long dp[n+1] = {0};
    dp[0] = 1;
    int len = res.size();

    for (int i=1; i<n; i++) {
        for (P curr : res) {
            for (int j=curr.first; j<=curr.second && j <= i; j++) {
                dp[i] += dp[i-j];
            }
        }
    }
    cout << dp[n-1] % mod << endl;
    // cout << dp[n-1] << endl;
    

    return 0;
}