#include<bits/stdc++.h>
using namespace std;
using ll=int64_t;
int main(){
  ll n,k,i,j,mod=998244353;
  cin>>n>>k;
  vector<ll> l(k),r(k),dp(n),d(n);
  for(i=0;i<k;i++) cin>>l[i]>>r[i];
  dp[0]=1;
  d[1]=-1;
  for(i=0;i<n;i++){
    if(i>0) dp[i]=(dp[i-1]+d[i]+mod)%mod;
    if(i<n-1){
      for(j=0;j<k;j++){
        if(i+l[j]<n){
          d[i+l[j]]=(d[i+l[j]]+dp[i]+mod)%mod;
          if(i+r[j]+1<n) d[i+r[j]+1]=(d[i+r[j]+1]-dp[i]+mod)%mod;
        }
      }
    }
  }
  cout<<dp[n-1]<<endl;
}