#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll unsigned long long int
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define pci pair<char,int
#define mii map<int,int>
#define mll map<long long int,long long int>
#define mci map<char,int>
#define umii unordered_map<int,int>
#define umll unordered_map<long long int,long long int>
#define umci unordered_map<char,int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define mod 998244353
using namespace std;
#define maxval 10003000
ll power(ll x,ll n)
{//ll x1=0;
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x);
       //  if(result>=1000000001) return 0;
        x=(x*x);
      //   if(x>=1000000001) return 0;
        n=n/2;
    }
    return result;
}
int vowel(char x){
    if(x=='a') return 1;
    if(x=='e') return 1;
    if(x=='i') return 1;
    if(x=='o') return 1;
    if(x=='u') return 1;
    return 0;
}
ll numb(ll x){ll z=sqrt(x);
if(z*z==x) return 1;
    return 0;
}
int main(){
   IOS;
ll t;t=1;//cin>>t;

while(t--){
ll  n,k;
cin>>n>>k;
vector<ll> a;
for(ll i=0;i<k;i++){
    ll x,y;cin>>x>>y;
    for(ll i=x;i<=y;i++) a.pb(i);
}
sort(a.begin(),a.end());
//cout<<a.size()<<"\n";
ll dp[n+1]={0};
dp[0]=1;
for(ll i=1;i<=n;i++){
    for(ll j=0;j<a.size();j++){
        if(i<a[j]) break;
       // if(i==5) cout<<dp[i-a[j]]<<" "<<a[j]<<"\n";
        dp[i]=(dp[i]+dp[i-a[j]])%mod;
        
    }
}
cout<<dp[n-1]<<"\n";

} 
    
    

    
return 0;    
}