#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)
const int MOD = 998244353;

// 参考
// https://atcoder.jp/contests/s8pc-1/submissions/15772604
template <int mod> struct ModInt {
    int x;

    ModInt() : x(0) {}

    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt &operator+=(const ModInt &p) {
        if ((x += p.x) >= mod)
            x -= mod;
        return *this;
    }

    ModInt &operator-=(const ModInt &p) {
        if ((x += mod - p.x) >= mod)
            x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }

    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt &p) const { return x == p.x; }

    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while (n > 0) {
            if (n & 1)
                ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() { return mod; }
};

using mint = ModInt<MOD>;

// http://kazune-lab.net/library/library/DataStructure/RangeAddQuery.cpp.html
// ----- RangeAddQuery -----
template <typename T = long long> class RangeAddQuery { // index starts at 0.
    int N;
    vector<T> data;

  public:
    RangeAddQuery(int N) : N{N}, data(N + 1, T{0}) {}

    T get(int i) { return _sum(i + 1); }

    void add(int a, int b, T x) { // [a, b)
        _add(a + 1, x);
        _add(b + 1, -x);
    }

  private:
    T _sum(int i) { // [1, i]
        T s{0};
        while (i > 0) {
            s += data[i];
            i -= i & -i;
        }
        return s;
    }

    void _add(int i, T x) {
        while (i <= N) {
            data[i] += x;
            i += i & -i;
        }
    }
};

void solve() {
    int N, K;
    cin >> N >> K;
    vector<pair<int, int>> v(K);
    for (auto &x : v) {
        cin >> x.first >> x.second;
    }
    sort(ALL(v));
    RangeAddQuery<mint> raq(N);
    raq.add(0, 1, 1);

    REP(i, N) {
        auto t = raq.get(i);
        for (auto &x : v) {
            raq.add(i + x.first, i + x.second + 1, t);
        }
    }
    cout << raq.get(N - 1) << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 4768