#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
vector<ll>S;ll mod=998244353;
ll solve(ll SUM,vector<ll>&X){
  if(X.at(SUM)==-1){
    ll ans=0;
    for(ll i=0;i<S.size()&&S.at(i)<=SUM;i++){
      ans+=solve(SUM-S.at(i),X);ans%=mod;if(X.at(SUM)!=-1)break;
    }
    if(X.at(SUM)!=-1)break;X.at(SUM)=ans%mod;
  }
  return X.at(SUM);
}
signed main(){
  ll N,K,i,j,L,R;cin>>N>>K;vector<ll>X(N,-1);
  REP(i,K){cin>>L>>R;FOR(j,L,R+1)S.push_back(j);}sort(ALL(S));
  REP(i,S.at(0))X.at(i)=0;X.at(i)=1;X.at(0)=1;
  cout<<solve(N-1,X)<<endl;
  return 0;
}
