/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>
#define ll long long

using namespace std;

ll dp[200003][200003];

vector<ll> s;

ll n;

ll solve(ll i, ll d){
    if(i+d==n) return (ll)1;
    if(i+d>n) return (ll)0;
    
    if(dp[i][d]!=-1) return dp[i][d];
    
    ll sum=0;
    for(auto ele:s){
        sum+=solve(i+d,ele)%(ll)998244353;
    }
    return dp[i][d]=sum;
}

ll ans(ll x){
    ll sum=0;
    for(auto ele:s) sum+=solve(x,ele)%(ll)998244353;
    return sum;
}

int main()
{
    ll k;
    cin>>n>>k;
    
    memset(dp,-1,sizeof(dp));
    
    for(ll i=0;i<k;i++){
        ll l,r;
        cin>>l>>r;
        for(ll j=l;j<=r;j++) s.push_back(j);
    }
    
    cout<<ans(1)<<'\n';
    
    return 0;
}
