#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 998244353;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

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 modint = ModInt<MOD>;

modint solve0(ll n, ll k, const vector<P> &a) {
    vector<modint> dp(n+10);
    modint cost = 0;
    dp[0] = 0;
    rep(i,n) {
        if (i == 0) cost = 1;
        cost += dp[i];
        for (const auto [l, r]: a) {
            if (i+l >= n) continue;
            dp[i+l] += cost;
            dp[min(n, i+r+1)] -= cost;
        }
        if (i == 0) cost = 0;
    }
    rep(i,n) dp[i+1] += dp[i];
    return dp[n-1];
}

template <class T>
class SegTree {
    int n; // number of leaves
    vector<T> data; // vector which has datas
    T def; // init number & 単位元
    function<T(T,T)> operation; // 区間クエリで使う処理
    function<T(T,T)> update; // 点更新で使う処理

    T _query(int a, int b, int k, int l, int r) {
        // [a, b)のクエリ
        // ノードk(区間[l, r)担当)が答える
        if (b <= l || r <= a) return def; // 区間がかぶらなければdef
        if (a <= l && r <= b) return data[k]; // 区間が完全にかぶっていればdata[k]
        else {
            // 一部だけかぶる場合は左右の子に委託する
            T c1 = _query(a, b, 2*k+1, l, (l+r)/2);
            T c2 = _query(a, b, 2*k+2, (l+r)/2, r);
            return operation(c1, c2);
        }
    }

    public:

        SegTree(size_t _n, T _def, function<T(T,T)> _operation, function<T(T,T)> _update) :
            def(_def), operation(_operation), update(_update){
                n = 1;
                while (n < _n) {n *= 2;}
                data = vector<T>(2*n-1, def);
        }

        T query(int a, int b) {return _query(a,b,0,0,n);}

        void change(int i, T x) {
            i += n-1;
            data[i] = update(data[i],x);
            while (i>0) {
                i = (i-1)/2;
                data[i] = operation(data[i*2+1], data[i*2+2]);
            }
        }

        T operator[](int i) {return data[i+n-1];}
};

modint solve1(ll n, ll k, const vector<P> &a) {
    SegTree<modint> dp((size_t)n+10, 0ll, [](modint a, modint b) { return a + b; }, [](modint a, modint b) { return a + b; });
    dp.change(0, 1);
    for (int i = 1; i <= n; ++i) {
        modint tmp = 0;
        for (const auto [y, x]: a) {
            int l = i-x; int r = i-y+1;
            if (r <= 0) continue;
            chmax(l, 0);
            tmp += dp.query(l,r);
        }
        dp.change(i, tmp);
    }

    return dp.query(n-1, n);
}

int main(int argc, char const *argv[]) {
    ll n,k; cin>>n>>k;
    vector<P> a(k);
    rep(i,k) cin>>a[i].first>>a[i].second;
    // cout << solve0(n,k,a) << '\n';
    cout << solve1(n,k,a) << '\n';
    return 0;
}

Measured memory_bytes: 5332