#include                        <bits/stdc++.h>
#include                        <ext/pb_ds/assoc_container.hpp>
#define lb                      lower_bound
#define ub                      upper_bound
#define fe(x)                   (*(x.begin()))
#define le(x)                   (*(x.rbegin()))
#define pb                      push_back
#define load(node,n)            bool operator < (const node &n) const
#define fbo(x,id)               (*(x.find_by_order(id)))
#define ook(y)                  order_of_key(y)
#define all(x)                  (x).begin(),(x).end()
#define FOR(i,n)                for(int i = 1; i<=n; i++)
#define REP(i,n)                for(int i = 0; i<n;  i++)
#define TT                      long long TC;  scanf("%lld",&TC);  while(TC--)
#define read                    freopen("input.txt","r",stdin)
#define write                   freopen("output.txt","w",stdout)
#define set(x)                  tree<x,null_type,less<x>,rb_tree_tag,tree_order_statistics_node_update>
using                           namespace __gnu_pbds;
using                           namespace std;
typedef                         long long ll;
typedef                         pair<ll,ll> pll;
typedef                         pair<int,int> pii;

const ll P = 998244353ll;

vector<ll> v;
#define mx 200003
ll dp[mx];

ll n,k;

ll fn(ll N){
    if(N>n) return 0;
    if(N==n)    return 1;
    ll &ans = dp[N];
    if(ans!=-1) return ans;
    ans = 0;
    for(ll i:v){// = 0; i<v.size(); i++){
        if(N+i<=n){
            ans = (ans + fn(N+i))%P;
        }
        else break;
    }
    return ans;
}


main(){
//read;

memset(dp,-1,sizeof dp);

scanf("%lld%lld",&n,&k);

for(ll i = 0; i<k; i++){
    ll a,b;
    cin>>a>>b;
    for(ll i = a; i<=b; i++)
        v.pb(i);
}

sort(all(v));
//for(ll i:v)
//    cout<<i<<" ";
//cout<<endl;
ll ans = fn(1);
cout<<ans;

return 0;
}
