#include <iostream>
#include <unordered_map>
#define ll long  long int
#define mod 998244353
using namespace std;
int main() {
    ll n,k;
    cin>>n>>k;
    ll dp[n+1]={0};
    dp[n]=1;
    ll a,b;
    unordered_map<ll,ll> m;
    for(ll i=0;i<k;i++)
    {
        cin>>a>>b;
        for(ll j=a;j<=b;j++)
        {
            if(m.count(j)==0)
            {
                m[j]=1;
            }
        }
    }
    for(int i=n-1;i>0;i--)
    {
        for(auto itr=m.begin();itr!=m.end();itr++)
        {
            if(((itr->first)+i)<=n)
            {
                dp[i]=(((dp[i]%mod)+(mod+dp[i+(itr->first)]%mod))%mod);
                dp[i]=dp[i]%mod;
            }
            /*if(((itr->first)+i)==n)
            {
                dp[i]=dp[i]+1;
                dp[i]=dp[i]%mod;
            }*/
        }
    }
    dp[1]=dp[1]%mod;
    cout<<dp[1]<<"\n";
    return 0;
}
