#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1<<30;
const ll inf_l = 1LL<<61;
const int MAX = 1e5;

const int mod = 998244353;
struct mint {
    ll x;
    mint (ll x = 0) : x((x%mod+mod)%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 += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator *=(const mint a) {(x *= a.x) %= mod; return *this;}
    mint operator +(const mint a) const {return mint(*this) += a;}
    mint operator -(const mint a) const {return mint(*this) -= a;}
    mint operator *(const mint a) const {return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {return pow(mod-2);}
    mint operator /=(const mint a) {return *this *= a.inv();}
    mint operator /(const mint a) {return mint(*this) /= a;}
};
istream& operator >>(istream &is, const mint &a) {return is >> a.x;}
ostream& operator <<(ostream &os, const mint &a) {return os << a.x;}

template<class T>
struct BIT {
    vector<T> bit;
    int n;
    BIT(int n): n(n), bit(n+1){}

    // 1-index
    void add(int i, T x) {
        while (i <= n) {
            bit[i] += x;
            i += i & -i;
        }
    }
    
    // a_1+a_2+...a_i
    T sum(int i) {
        T s = 0;
        while (i > 0) {
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }

    // [l,r)の合計
    T sum(int l, int r) {
        return sum(r-1) - sum(l-1);
    }

    // min{x|a_1+a_2+...+a_x >= w}
    int lower_bound(int w) {
        if (w <= 0) return 0;
        int x = 0, r = 1;
        while (r < n) r <<= 1;
        for (int len = r; len > 0; len = len >> 1) {
            if (x + len < n && bit[x+len] < w) {
                w -= bit[x+len];
                x += len;
            }
        }
        return x + 1;
    }
};

mint dp[200005];

int main() {
    int n, k; cin >> n >> k;
    vector<P> data(k);
    rep(i,k) {
        int l, r; cin >> l >> r;
        data[i] = P(l,r);
    }
    BIT<mint> bit(200005);
    dp[1] = 1;
    bit.add(1,1);
    for (int i = 2; i <= n; i++) {
        rep(j,k) {
            int l = max(i-data[j].second,1);
            int r = i - data[j].first;
            if (r < 1) continue;
            dp[i] += bit.sum(l,r+1);
        }
        bit.add(i,dp[i]);
    }
    mint ans = dp[n];
    cout << ans << endl;
}

Measured memory_bytes: 6428