#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define rep(i,n) for (int i = 0; i < n; ++i)
#define REP(i,k,n) for (int i = k; i <= n; ++i)
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define vin(v, N) vi v; rep(i, N) {int x; cin >> x; v.push_back(x);}

#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)

const int MAX_N = 2e5 + 5;

long dp[MAX_N];
void solve() {
    memset(dp, 0, sizeof(dp));
    int N, K;
    cin >> N >> K;
    vi v;
    rep(i, K) {
        int l, r;
        cin >> l >> r;
        REP(j, l, r) {
            v.push_back(j);
        }
    }
    dp[0] = 1;
    REP(i, 1, N-1) {
        for (auto move : v) {
            if (i-move >= 0) {
              dp[i] = (dp[i]+dp[i-move]) % 998244353;
            }
        }
    }
    cout << dp[N-1];
}

//#define LOCAL 1

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    solve();

    return 0;
}
