#include<bits/stdc++.h>
using namespace std;
typedef		 long long int    ll;
typedef		 long double   ld;
typedef		vector<ll>      vll;
#define     fi              first
#define     print(v)        for(ll i:v) cout<<i<<ss
#define     se              second
#define		pb              push_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		ss              ' '
#define     pii             pair<ll,ll>
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
const double eps = 1e-8;


int main()
{
//    ios::sync_with_stdio(0);
//    cin.tie(0);
    ll mod=998244353;
    ll n;
    cin>>n;
    ll m;
    cin>>m;
    vector<pii>vp;
    for(ll i=1; i<=m; i++)
    {
        ll a,b;
        cin>>a>>b;
        vp.pb({a,b});
    }
    ll dp[n+10];
    memset(dp,0,sizeof(dp));
    dp[1]=1;
    for(ll i=1; i<=n; i++)
    {

        ll cur=dp[i];
        ll pp[n+10]= {0};
        for(ll j=0; j<m; j++)
        {
            ll l=vp[j].fi;
            ll r=vp[j].se;
            ll a=i+l;
            ll b=i+r+1;
            if(a<=n)
                pp[a]+=cur;
            if(b<=n)
                pp[b]-=cur;


        }
        for(ll j=i+1; j<=n; j++)
            pp[j]+=pp[j-1];
        for(ll j=1; j<=n; j++)
        {
            dp[j]+=pp[j];
            dp[j]%=mod;
            //  cout<<dp[j]<<ss;
        }
        // cout<<nn;


        // break;
    }

    cout<<dp[n]<<nn;



}


/* Final check before submit :

1. array size or integer overflow,like uninitialised 0 index.

2. Think twice,code once.check all possible counter test case.

3. Be careful about corner case! n=1?k=1? something about 0?

4. avoid stupid mistake!complexity(t/m)?precision error?submit same code twice?

5. if got WA than remember that you are missing something common.
   *** Be confident!!! who knows? may be your one step back to AC ***
4. minus mod ans=(ans-k+mod)%mod;

*/




