#include <bits/stdc++.h>

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,N,j) for(int i = (N-1);i >= (j);i--)
#define _rec(i,N,j) for(int i = (N);i >=(j);i--)
#define ALL(x) x.begin(),x.end()
#define MEM(a,n) memset(a,n,sizeof(a))
#define fst first
#define scd second
#define PB push_back
#define MP make_pair


typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

int get_int(){int x;scanf("%d",&x);return x;}
LL get_ll(){LL x;scanf("%lld",&x);return x;}
double get_db(){double x;scanf("%lf",&x);return x;}

template<typename T> int chmin(T &a,T b){if(a > b){a = b;return 1;}else return 0;}
template<typename T> int chmax(T &a,T b){if(a < b){a = b;return 1;}else return 0;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {_for(i,0,v.size()) os << v[i] << " ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){for(auto a:v) os << a <<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){os << v.fst <<" "<<v.scd << " ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& v){for(auto a:v) cout << a << endl;return os;}

static const int dx[8] = { -1,  0, 1, 0,  1, -1,  1, -1};
static const int dy[8] = {0,  1, 0,  -1,  1, -1, -1,  1};
const double pi  = acos(-1.0);
const double eps = 1e-8;
const LL  INF  = 0x3f3f3f3f3f3f3f3f;
const int inf  = 0x3f3f3f3f;

template <int mod>
struct mint{
  int x;
  constexpr mint() : x(0) {}
  constexpr mint(LL y): x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  constexpr mint &operator+=(const mint &p){if((x += p.x) >= mod) x -= mod;return *this;}
  constexpr mint &operator-=(const mint &p){if((x += mod - p.x) >= mod) x -= mod;return *this;}
  constexpr mint &operator*=(const mint &p) noexcept {x = (int)(1LL * x * p.x % mod);return *this;}
  constexpr mint &operator/=(const mint &p) noexcept {*this *= p.inv();return *this;}
  constexpr mint operator-() const {return mint(-x);}
  constexpr mint operator+(const mint &p) const{return mint(*this) += p;}
  constexpr mint operator-(const mint &p) const{return mint(*this) -= p;}
  constexpr mint operator*(const mint &p) const{return mint(*this) *= p;}
  constexpr mint operator/(const mint &p) const{return mint(*this) /= p;}
  constexpr bool operator==(const mint &p) const{return x == p.x;}
  constexpr bool operator!=(const mint &p) const{return x != p.x;}
  constexpr bool operator <(const mint &p) const{return x < p.x;}
  constexpr bool operator >(const mint &p) const{return x > p.x;}
  constexpr mint inv() const { return this->power(mod - 2);}
  constexpr mint operator^(LL n) const { return mint(this->power(n)); }
  constexpr mint &operator^=(LL n) { return *this = *this ^ n; }
  constexpr int get_mod() { return mod;}
  constexpr mint power(LL n) const {
    mint res(1), mul(x);
    while(n) {
        if(n & 1)
        res *= mul;
        mul *= mul;
    n >>= 1;
    }
    return res;
  }
   inline mint fac() const {
        static std::vector<mint> facs;
        int l0 = facs.size();
        if (l0 > this->x) return facs[this->x];
        facs.resize(this->x + 1);
        for (int i = l0; i <= this->x; i++) facs[i] = (i == 0 ? mint(1) : facs[i - 1] * mint(i));
        return facs[this->x];
    }
    mint nCr(const mint &r) const {
        if (this->x < r.x) return mint(0);
        return this->fac() / ((*this - r).fac() * r.fac());
  }
  friend constexpr ostream &operator<<(ostream &os, const mint &p){return os << p.x;}
  friend constexpr istream &operator>>(istream &is,mint &a){LL t = 0;is >> t;a = mint<mod>(t);return (is);}
};
constexpr LL MOD = 998244353;
using mi = mint<MOD>;
const int maxn = 2e5 + 5;


mi step[maxn];
vector<pii> vp;
int N,K;

template <class T>
class SegTree {
    int n;                       // 葉の数
    vector<T> data;              // データを格納するvector
    T def;                       // 初期値かつ単位元
    function<T(T, T)> operation; // 区間クエリで使う処理
    function<T(T, T)> update;    // 点更新で使う処理

    // 区間[a,b)の総和。ノードk=[l,r)に着目している。
    T _query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return def; // 交差しない
        if (a <= l && r <= b)
            return data[k]; // a,l,r,bの順で完全に含まれる
        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:
    // _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数,
    // _update:更新関数
    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);
    }

    // 場所i(0-indexed)の値をxで更新
    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]);
        }
    }

    // [a, b)の区間クエリを実行
    T query(int a, int b) {
        return _query(a, b, 0, 0, n);
    }

    // 添字でアクセス
    T operator[](int i) {
        return data[i + n - 1];
    }
};





/*
mi searching(int v){
    if(step[v].x != -1){
        return step[v];
    }
    _for(i,0,K){
        int a = vp[v].first;
        int b = vp[v].second;
        if()
    }

}
*/

int main()
{
    cin >> N >> K;
    //step[1] = mi(1);
    _for(i,0,K){
        int a,b;
        cin >> a >> b;
        vp.PB(MP(a,b));
    }

    sort(ALL(vp));

    SegTree<mi> st(maxn,mi(0),[](mi a,mi b){return a + b;},[](mi a,mi b){return b;});
    st.change(1,1);

    _for(t,2,N+1){
        mi res(0);
        _for(i,0,K){
            int a = vp[i].first;
            int b = vp[i].second;
            if(t - a < 1) break;
            res += st.query(max(t - b,1),t - a + 1);
        }
        //cout << res << endl;
        st.change(t,res);
    }
    cout << st.query(N,N+1) << endl;


    return 0;
}


Measured memory_bytes: 5380