#include<bits/stdc++.h>
using namespace std;
#define int long long
int mod = 998244353; 
int32_t main(){
    int n,k;
    cin>>n>>k;
    int dp[n+1]={0};
    vector<int>  jump;
    int l,r;
    for(int i=0;i<k;++i){
        cin>>l>>r;
        for(int j=l;j<=r;++j){
            jump.push_back(j);
        }
    }
    
    int jlen  = jump.size();
    sort(jump.begin(),jump.end());
    // cout<<" pos "<<jlen;
    dp[0]=1;
    dp[1]=1;

    for(int i=2;i<=n;++i){
        // cout<<"\n i is" <<i;
        int c = 0;
        dp[i]=0;
          for(int j=0;j<jlen;++j){
            //   cout<<"val is"<<jump[j];
              if(i - jump[j] >= 1 ) {
                //   cout<<" changinf "<<i ;
                  dp[i]= ((dp[i-jump[j]]%mod) + (dp[i]%mod))%mod;
              }else{
                  break;
              }
          }
          
    }
 
//   cout<<"\njump\n";
//   for(int j=0;j<jlen;++j){
//       cout<<jump[j]%mod<<" ";
//   }

     

//     cout<<" dp array ";
//     cout<<" \n";
//      for(int i=1;i<=n;++i){
//          cout<<dp[i]<<" ";
//      }
    cout<<dp[n];

    
    return 0;
}
