#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const long long MOD = 998244353;

template<const long long MOD>
class Modint{
    public:
        Modint() : x(0) {

        }

        Modint(long long y) : x((y % MOD + 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 = 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 !(*this == p);
        }

        bool operator<(const Modint& p) const {
            return x < p.x;
        }

        bool operator>(const Modint& p) const {
            return x > p.x;
        }

        bool operator<=(const Modint& p) const {
            return !(*this > p);
        }

        bool operator>=(const Modint& p) const {
            return !(*this < p);
        }

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

        Modint pow(long long 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){
            long long t;
            cin >> t;
            a = Modint<MOD>(t);
            return is;
        }

        explicit operator long long() const {
            return x;
        }

        static long long get_mod(){
            return MOD;
        }

    private:
        long long x;
};

template<typename T>
class FenwickTree{
    public:
        // 0-indexed
        FenwickTree(int N){
            data.assign(++N, 0);
        }

        // sum of [0, k)
        T sum(int k){
            T ret = 0;
            for(; k > 0; k -= k & -k) ret += data[k];
            return ret;
        }

        // add x to k-th
        void add(int k, T x){
            for(++k; k < data.size(); k += k & -k) data[k] += x;
        }

    private:
        vector<T> data;
};


template<typename T>
class RangedFenwickTree{
    public:
        // 0-indexed
        RangedFenwickTree(int N) : bit0(N), bit1(N) {

        }

        // sum of [0, k)
        T sum(int k){
            return bit0.sum(k) + (T)k * bit1.sum(k);
        }

        // add x to [l, r)
        void add(int l, int r, T x){
            bit0.add(l, -x * l);
            bit0.add(r, x * r);
            bit1.add(l, x);
            bit1.add(r, -x);
        }

    private:
        FenwickTree<T> bit0, bit1;
};

ll N, K;
vector<pll> S;
using mint = Modint<MOD>;

signed main(){
    cin >> N >> K;
    ll l, r;
    REP(i, K){
        cin >> l >> r;
        S.push_back({l, r});
    }
    RangedFenwickTree<mint> bit(N + 1);
    bit.add(0, 1, 1);
    REP(i, N){
        for(auto p : S){
            bit.add(i + p.first, i + p.second + 1, bit.sum(i + 1) - bit.sum(i));
        }
    }
    PRINT(bit.sum(N) - bit.sum(N - 1));
    return 0;
}

Measured memory_bytes: 6344