    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <cmath>

    using namespace std;
#define int long long

    const int mod = 998244353;

    int32_t main() {
        int n, k;
        cin >> n >> k;
        vector<int> dp(n, 0);
        dp[0] = 1;
        vector<int> ps(2, 0);
        ps[1] = 1;
        vector<int> l(k), r(k);
        for(int i = 0; i < k; ++i) {
            cin >> l[i] >> r[i];
        }
        for(int i = 1; i < n; ++i) {
            for(int j = 0; j < k; ++j) {
                int lg, rg;
                if (i - l[j] < 0) continue;
                rg = max(0, i - l[j]);
                lg = max(0, i - r[j]);
                dp[i] += ps[rg + 1] - ps[lg];
            }
            ps.push_back((ps.back() + dp[i]) % mod);
            dp[i] %= mod;
        }
        cout << dp[n - 1];
    }
