#if loc||local
#define _GLIBCXX_DEBUG
#endif

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

#define rep(i,n) for(ll i=0;i<ll(n);++i)
#define repr(i,n) for(ll i=ll(n);i-->0;)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
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(a>b){a=b;return 1;}return 0;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

template<class T,class F>
struct segment_tree{
  std::vector<T> data;
  int n;F f;T identity;
  segment_tree(){}
  segment_tree(int sz,T ide,F _f):f(_f),identity(ide){
    n=1;while(n<sz)n<<=1;
    data.resize(2*n,identity);
  }
  segment_tree(std::vector<T> const& v,T ide,F _f):f(_f),identity(ide){
    build(v);
  }
  void build(std::vector<T> const& v){
    int sz=v.size();
    n=1;while(n<sz)n<<=1;
    data.resize(2*n,identity);
    for(int i=0;i<sz;++i)data[i+n]=v[i];
    for(int i=n-1;i>0;--i)data[i]=f(data[i<<1|0],data[i<<1|1]);
  }
  void set(int i,T x){
    i+=n;data[i]=x;
    while(i,i>>=1)data[i]=f(data[i<<1|0],data[i<<1|1]);
  }
  T fold(int l,int r)const{
    l+=n,r+=n;
    T fold_l=identity,fold_r=identity;
    while(l<r){
      if(l&1)fold_l=f(fold_l,data[l++]);
      if(r&1)fold_r=f(data[--r],fold_r);
      l>>=1,r>>=1;
    }
    return f(fold_l,fold_r);
  }
  T operator[](int i)const{return data[i+n];}
  template<class Cond>int bserch(int l,Cond& cond){
    l+=n;T x=identity;
    do{
      while(!l&1)l>>=1;if(cond(f(x,data[l]))){
        while(l<n){l<<=1;if(!cond(f(x,data[l])))x=f(x,data[l++]);}
        return l-n;
      }x=f(x,data[l++]);
    }while((l&-l)!=l);
    return -1;
  }
};
template<class T,class F>
auto make_segtree(int n,T ide,F f){
  return segment_tree<T,F>(n,ide,f);
}
template<class T,class F>
auto make_segtree(std::vector<T>const& v,T ide,F f){
  return segment_tree<T,F>(v,ide,f);
}
struct union_find{
  size_t n;
  std::vector<int> par;
  size_t group;
  union_find(){}
  union_find(size_t _n):n(_n),group(_n){
    par.resize(n,-1);
  }
  void reset(size_t _n){
    n = _n;
    group = n;
    par.clear();
    par.resize(n,-1);
  }
  int root(int k){
    if(par[k]<0)return k;
    return par[k] = root(par[k]);
  }
  int size(int k){
    k = root(k);
    return -par[k];
  }
  int operator[](int k){
    return size(k);
  }
  bool unite(int a,int b){
    a = root(a);
    b = root(b);
    if(a==b)return false;
    if(size(a)<size(b))std::swap(a,b);
    group--;
    par[a] += par[b];
    par[b] = a;
    return true;
  }
  bool operator()(int a,int b){
    return unite(a,b);
  }
  bool same(int a,int b){
    return root(a) == root(b);
  }
};
namespace ate{
  template<int64_t p>
  struct F_p{
    using value_type = int64_t;
    static constexpr inline value_type get_mod(){return p;}

    value_type value;

    constexpr F_p():value(value_type{}){}
    template<class T>constexpr F_p(T v):value(static_cast<value_type>(v<0?v%p+p:v%p)){}
  // operator +, -, *, /, ^ 
    constexpr F_p operator + (const F_p& other)const{
      return F_p(*this) += other;
    }
    constexpr F_p operator - (const F_p& other)const{
      return F_p(*this) -= other;
    }
    constexpr F_p operator * (const F_p& other)const{
      return F_p(*this) *= other;
    }
    constexpr F_p operator / (const F_p& other)const{
      return F_p(*this) /= other;
    }
    template<class T> constexpr F_p operator ^ (const T other)const{
      return F_p(*this) ^= other;
    }
    constexpr F_p &operator += (const F_p& other){
      value+=other.value;
      if(value>p)value-=p;
      return *this;
    }
    constexpr F_p &operator -= (const F_p& other){
      value-=other.value;
      if(value<0)value+=p;
      return *this;
    }
    constexpr F_p &operator *= (const F_p& other){
      value*=other.value;
      if(value>p)value%=p;
      return *this;
    }
    constexpr F_p &operator /= (const F_p& other){
      value*=other.inverse();
      if(value>p)value%=p;
      return *this;
    }
    template<class T>
    constexpr F_p &operator ^= (const T n){
      value = mpow(n).value;
      return *this;
    }
  // ext_gcd,inverse,mpow 
    static constexpr value_type ext_gcd(value_type a,value_type b,value_type& x,value_type& y){
      if(b==0){x=1,y=0;return a;}
      value_type d=ext_gcd(b,a%b,y,x);
      y-=a/b*x;return d;
    }
    constexpr value_type inverse()const{
      value_type x,y;
      ext_gcd(value,p,x,y);
      return x<0?x%p+p:x%p;
    }
    template<class T>
    static constexpr value_type inverse(T val){
      value_type x,y;
      ext_gcd(val,p,x,y);
      return x<0?x%p+p:x%p;
    }
    template<class T>
    constexpr F_p mpow(T n)const{
      F_p res(1),vn(*this);
      while(n){
        if(n&1)res*=vn;
        vn*=vn;
        n>>=1;
      }
      return res;
    }
    template<class T,class U>
    static constexpr T mpow(T a,U b){
      F_p x(a);
      return static_cast<T>(x.mpow(b).value);
    }
  // operator iostream 
    constexpr friend std::istream &operator >> (std::istream& is,F_p& fp){
      is>>fp.value;
      return is;
    }constexpr friend std::ostream &operator << (std::ostream& os,const F_p& fp){
      os<<fp.value;
      return os;
    }
  //operator bool
    constexpr bool operator == (const F_p& other)const{
      return value == other.value;
    }
  };
}
using mint = ate::F_p<(int)998244353>;

template<class T,class U,class F,class G,class H>
struct lazy_segment_tree{
  std::vector<T> data;
  std::vector<U> lazy;
  int n,height;
  F merge;
  G mapping;
  H composition;
  T ti;
  U ui;
  lazy_segment_tree(){}
  lazy_segment_tree(std::vector<T>const& v,T ide1,U ide2,F f,G g,H h)
    :ti(ide1),ui(ide2),merge(f),mapping(g),composition(h)
  {
    int sz = std::size(v);
    n=1,height=0;
    while(n<sz)n<<=1,height++;
    data.resize(n<<1,ti);
    lazy.resize(n<<1,ui);
    for(int i=0;i<sz;++i)
      data[i+n] = v[i];
    for(int i=n;i-->0;)
      data[i] = merge(data[i<<1|0],data[i<<1|1]);
  }
  inline T reflect(int k){
    return lazy[k]==ui?data[k]:mapping(data[k],lazy[k]);
  }
  inline void evaluate(int k){
    if(lazy[k]==ui)return;
    if(k<n){
      lazy[k<<1|0] = composition(lazy[k<<1|0],lazy[k]);
      lazy[k<<1|1] = composition(lazy[k<<1|1],lazy[k]);
    }
    data[k] = reflect(k);
    lazy[k] = ui;
  }
  inline void propagate(int k){
    for(int i=height;i>=0;--i)evaluate(k>>i);
  }
  inline void recalc(int k){
    while(k>>=1)data[k] = merge(reflect(k<<1|0),reflect(k<<1|1));
  }
  void update(int a,int b,U v){
    a+=n;b+=n;propagate(a);propagate(b-1);
    for(int l=a,r=b;l<r;l>>=1,r>>=1){
      if(l&1)lazy[l] = composition(lazy[l],v),l++;
      if(r&1)--r,lazy[r] = composition(lazy[r],v);
    }
    recalc(a);recalc(b-1);
  }
  T fold(int a,int b){
    a+=n;b+=n;propagate(a),propagate(b-1);
    T lef_v(ti),rig_v(ti);
    for(int l=a,r=b;l<r;l>>=1,r>>=1){
      if(l&1)lef_v = merge(lef_v,reflect(l)),l++;
      if(r&1)--r,rig_v = merge(reflect(r),rig_v);
    }
    return merge(lef_v,rig_v);
  }
};
template<class T,class U,class F,class G,class H>
auto make_lseg(std::vector<T> v,T ide1,U ide2,F f,G g,H h){
  return lazy_segment_tree<T,U,F,G,H>(v,ide1,ide2,f,g,h);
}
signed main(){

  ll n,k;
  cin>>n>>k;
  vector<int> a(n+1);
  vector<pair<int,int>> sect(k);
  rep(i,k){
    int l,r;
    cin>>l>>r;
    sect[i] = {l,r};
    for(int j=l;j<=r;++j)a[j]=1;
  }
  sort(begin(sect),end(sect));

  struct ushi{
    mint val,sz;
    ushi():val(),sz(1){}
    ushi(mint v,mint s):val(v),sz(s){}
  };
  auto f = [](ushi a,ushi b){return ushi(a.val+b.val,a.sz+b.sz);};
  auto g = [](ushi a,mint b){return ushi(a.val+a.sz*b,a.sz);};
  auto h = [](mint a,mint b){return a+b;};
  ushi ti = ushi(0,1);
  mint ui = 0;
  vector<ushi> tmp(n*3);
  auto dp = make_lseg<ushi,mint>(tmp,ti,ui,f,g,h);
  // range add range sum
  dp.update(1,1+1,1);
  for(int i=1;i<n;++i){
    ushi tapu = dp.fold(i,i+1);
    mint v = tapu.val;
    rep(j,k){
      auto&[l,r]=sect[j];
      dp.update(i+l,i+r+1,v);
    }
  }
  ushi tapu = dp.fold(n,n+1);
  mint ans = tapu.val;
  cout<<(ans)<<endl;

}

Measured memory_bytes: 71912