#include<bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long

ll MOD = 998244353;

ll add_mod(ll a, ll b) {
    a %= MOD, b %= MOD;
    return (a + b) % MOD;
}

void solve()
{
    ll n,k;
    cin>>n>>k;
    set<ll> s;
    for(ll i=0;i<k;i++)
    {
        ll x,y;
        cin>>x>>y;
        for(ll j=x;j<=y;j++) s.insert(j);
    }

    ll dp[n+4]={0};
    ll val_int=*s.begin();
    dp[val_int]=1;
    for(ll i=1;i<=n;i++)
    {
        for(auto it:s)
        {
            ll val=it;
            if(i-val>=0) 
            {
                dp[i]=add_mod(dp[i],dp[i-val]);
            }
        }
    }
    cout<<dp[n];
}

int32_t main()
{
    IOS
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++) solve();
    return 0;
}