#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
ll gcd(ll a, ll b);
int main(){
cin.tie(0);
ll n,k,ml,mr;
cin>>n>>k;
vector<ll> move;
ll l[n],r[n],dp[n]={};
dp[0]=1;
for(ll i=0;i<k;i++){
    cin>>l[i]>>r[i];
    for(ll t=l[i];t<=r[i];t++){
        move.push_back(t);
    }
    ml=min(l[i],ml);
    mr=max(r[i],mr);
}
for(ll i=0;i<n;i++){
    for(ll c=ml;c<=min(i,mr);c++){
      	if(find(move.begin(),move.end(),c)!=move.end())dp[i]+=dp[i-c];
    }
}
cout<<dp[n-1]%998244353;
return 0;
}






ll gcd(ll a, ll b){

   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }

}