#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 998244353;

struct mint {
    long long x;
    mint(long long x=0):x(x % MOD + (0 <= x ? 0 : MOD)) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint& a) { if ((x += a.x) >= MOD) x -= MOD; return *this; }
    mint& operator-=(const mint& a) { if ((x -= a.x) < 0) x += MOD; return *this; }
    mint& operator*=(const mint& a) { (x *= a.x) %= MOD; return *this; }
    mint operator+(const mint& a) const { return mint(x) += a; }
    mint operator-(const mint& a) const { return mint(x) -= a; }
    mint operator*(const mint& a) const { return mint(x) *= a; }

    // for prime mod
    mint inv() const {
        long long a = x, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        return mint(u);
    }
    mint& operator/=(const mint& a) { return *this *= a.inv(); }
    mint operator/(const mint& a) const { return mint(x) /= a; }
};
istream& operator>>(istream& is, const mint& a){ return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a){ return os << a.x; }

template<typename T>
 struct LazySegmentTree {
 
 private:
     int n;
     T init_v;
     vector<T> node;
     vector<T> lazy;
 
 public:
     LazySegmentTree(vector<T> a, T _init_v) {
 
         n = 1;
         init_v = _init_v;
 
         int sz = a.size();
         while (n < sz) n *= 2;
 
         node.resize(2 * n, init_v);
         lazy.resize(2 * n, init_v);
 
         for (int i = 0; i < sz; i++) node[i + n - 1] = a[i];
         for (int i = n - 2; i >= 0; i--) node[i] = (node[i * 2 + 1] + node[i * 2 + 2]) % MOD;
     }
 
     void eval(int k, int l, int r) {
         if (lazy[k] != 0) {
             node[k] += lazy[k];
             node[k] %= MOD;
             if (r - l > 1) {
                 lazy[k * 2 + 1] += (mint(lazy[k]) / 2).x;
                 lazy[k * 2 + 1] %= MOD;
                 lazy[k * 2 + 2] += (mint(lazy[k]) / 2).x;
                 lazy[k * 2 + 2] %= MOD;
             }
             lazy[k] = 0;
         }
     }
 
     void add(int a, int b, T x, int k = 0, int l = 0, int r = -1) {
         if (r < 0) r = n;
         eval(k, l, r);
         if (r <= a || b <= l) return;
         if (a <= l && r <= b) {
             lazy[k] += (r - l) * x % MOD;
             lazy[k] %= MOD;
             eval(k, l, r);
         } else {
             add(a, b, x, k * 2 + 1, l, (l + r) / 2);
             add(a, b, x, k * 2 + 2, (l + r) / 2, r);
             node[k] = (node[k * 2 + 1] + node[k * 2 + 2]) % MOD;
         }
     }
 
     T getsum(int a, int b, int k = 0, int l = 0, int r = -1) {
         if (r < 0) r = n;
         eval(k, l, r);
         if (r <= a || b <= l) return 0;
         if (a <= l && r <= b) return node[k];
         T lv = getsum(a, b, k * 2 + 1, l, (l + r) / 2);
         T rv = getsum(a, b, k * 2 + 2, (l + r) / 2, r);
         return (lv + rv) % MOD;
     }
 
 };

int main(){
    int N, K;
    cin >> N >> K;

    vector<P> V(K);
    rep(i, N) cin >> V[i].first >> V[i].second;

    sort(V.begin(), V.end(), [](P a, P b){return a.second < b.second;});

    vector<ll> dp(N);
    dp[0] = 1;
    LazySegmentTree<ll> st(dp, 0);

    rep(i, N) {
        rep(j, K) {
            auto [l, r] = V[j];
            if (N <= i + l) continue;
            ll pre = st.getsum(i, i+1);
            st.add(i+l, min(i+r+1, N), pre);
        }
    }

    mint ans = st.getsum(N-1, N);
    cout << ans << endl;
}

Measured memory_bytes: 14616