#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;
        if(m.count(a)==0)
        {
            m[a]=1;
        }
        if(m.count(b)==0)
        {
            m.insert(make_pair(b,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]+dp[i+(itr->first)];
                dp[i]=dp[i]%mod;
            }
            /*if(((itr->first)+i)==n)
            {
                dp[i]=dp[i]+1;
                dp[i]=dp[i]%mod;
            }*/
        }
    }
    cout<<dp[1]<<"\n";
    return 0;
}
