#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
//#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x,m) (((x)%m*(x)%m)%m)%m
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const ll mod2           = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll mod     = 998244353;
//#define N 1000001
const ll N2      = 70;
const ld PI      = 3.141592653589793;
//template<class T>using onset=tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}
void solve(){
  #ifndef ONLINE_JUDGE  
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
}
int f(vector<ll> arr,ll m,ll N){ 

    int count[N + 1]={0};
    count[0] = 1; 
    for (int i = 1; i <= N; i++) 
        for(int j = 0; j < m; j++) 
         if (i >= arr[j]) 
          count[i]=(count[i - arr[j]]%mod+count[i]%mod)%mod; 

      

    // required number of ways  

    return count[N]%mod;  

      
} 
signed main(){
    fastio();
    ll n,k;
    cin>>n>>k;
    set<ll>s; 
    while(k--){
      ll l,r;
      cin>>l>>r; 
      for(ll i=l;i<=r;i++){
        s.insert(i);
      }
    }
    vector<ll>p;
    for(auto i:s){
      p.pb(i);
    }
    ll ans=f(p,(ll)p.size(),(n-1));
    cout<<ans; 
    //printclock;
    return 0;
}