#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define db pop_back
#define q2(n) (n%2)==0
#define vp vector<pair <ll,ll> >
#define vctr vector<ll>
#define in(a) cin>>a;
#define out(a) cout<<a<<"\n";
#define nxt() cout<<"\n";
#define no() cout<<"No\n";
#define yes() cout<<"Yes\n";
#define bug1() cout<<"@ ";
#define bug2() cout<<"# ";
#define ff first
#define ss second
#define ip(n) ll n; cin>>n;
#define ipar(ar,n) ll ar[n]; loop(i,0,n) cin>>ar[i];
#define opar(ar,n) loop(i,0,n) cout<<ar[i]<<" ";
#define loop(i,m,p) for (ll i = m; i < p; i++)
#define loopn(i,m,p) for (ll i = p-1; i >=m; --i)

using namespace std;

int main()
{
     ll t=1;
  //ip(t)
  while(t--)
  {
     ip(n) ip(k)
     ll l[k],r[k];
     loop(i,0,k)
     {
         cin>>l[i]>>r[i];
     }
     vctr v,vv;
     loop(i,0,k)
     {
         loop(j,l[i],r[i]+1)
         {
             v.pb(j);
         }
     }
     sort(v.begin(),v.end());
     ll sz=v.size(),mod=998244353;
     vv.pb(v[0]);
     loop(i,1,sz)
     {
         if(v[i]!=v[i-1])
            vv.pb(v[i]);

     }
     sz=vv.size();
     ll dp[n]={0};
     dp[0]=1;
     loop(i,0,n)
     {
         loop(j,0,sz)
         {
             ll idx=i+vv[j];
             if(idx>=n)
                break;
            if(dp[i]>0)
             dp[idx]=(dp[idx]%mod)+(dp[i]%mod);
             dp[idx]%=mod;
         }
     }
   //  opar(dp,n) nxt()
     out(dp[n-1])



  }

return 0;
}


