#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back

// g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -o 

int main(){
 const ll mod=998244353;
 ll n,k;
 cin>>n>>k;
 set<ll>s;
 for(ll i=0;i<k;i++){
  ll x,y;
  cin>>x>>y;
  for(ll l=x;l<=y;l++){
   s.insert(l);
  }
 }
 ll dp[n+1]={0};
 dp[0]=1;
 for(ll i=1;i<=n;i++){
  for(auto x:s){
   if(i>=x)dp[i]=dp[i]+dp[i-x]%mod;
  }
 }
 cout<<dp[n-1]%998244353<<"\n";
 return 0;
}
