#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vb = vector<bool>;
using vs = vector<string>;
using vvi = vector<vi>;
using vp = vector<pii>;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define each(x, a) for (auto&& x : (a))
#define _overload3(_1, _2, _3, name, ...) name
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) for (int i = (a), i##_len = (n); i < i##_len; ++i)
#define rep(...) _overload3(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
constexpr int inf = (1LL<<31) - 1;
constexpr int mod = 1e9 + 7;
constexpr double eps = 1e-10;
constexpr int dx[] = {1, 0, -1, 0};
constexpr int dy[] = {0, 1, 0, -1};
template<class T> constexpr void print(const T& t) { cout << t << "\n"; }
template<class T, class U> constexpr bool chmax(T& a, const U& b) { if (a < b) a = b; return a < b; }
template<class T, class U> constexpr bool chmin(T& a, const U& b) { if (a > b) a = b; return a > b; }
template<class T, class U> istream& operator>>(istream& is, pair<T, U>& p) { is >> p.fi >> p.se; return is; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.fi << " " << p.se; return os; }
template<class T> istream& operator>>(istream& is, vector<T>& v) { each(e, v) is >> e; return is; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& v) { each(e, v) os << e << " "; return os; }
struct Init { Init() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); }} init;

int main() {
    const int m = 998244353;
    int n, k;
    cin >> n >> k;
    set<int> s;
    rep(i, k) {
        int l, r;
        cin >> l >> r;
        rep(j, l, r + 1) {
            s.insert(j);
        }
    }
    vi dp(n, 0);
    dp[0] = 1;

    rep(i, n) {
        each(d, s) {
            dp[i + d] += dp[i];
            dp[i + d] %= m;
        }
    }
    print(dp[n-1]);
}