#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include<chrono>
#include<typeinfo>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds; 
#define lli long long int
#define fr(i,a,b) for(lli i=a;i<b;i++)
#define bfr(i,a,b) for(lli i=a;i>=b;i--)
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL);
#define tc int t;cin>>t;while(t--)
#define mod 1000000007LL
#define mod2 998244353LL
#define all(vec) vec.begin(),vec.end()  
#define ld long double
#define pb push_back
#define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update> 

lli power(lli x,lli y)
{
     lli res=1;
     while(y>0)
     {
        if(y&1)res = ((res%mod)*(x%mod))%mod;
        y>>=1;
        x= ((x%mod)*(x%mod))%mod;
     }
     return res;
}

int main()
{
    
         

    fio

    lli n,k;
    cin>>n>>k;
    lli dis[n+2];
    fr(i,0,n+2)dis[i]=0;
    vector<lli> v;
    fr(i,0,k)
    {
        lli x,y;
        cin>>x>>y;
        fr(j,x,y+1){v.push_back(j);}
    }
    sort(all(v));
   // for(auto z:v)cout<<z<<" ";

    dis[1]=1;

    fr(i,2,n+1)
    {
        lli j=0;
        while(j<v.size() && v[j]<i)
        {if(dis[i-v[j]]!=-1)dis[i]=((dis[i]%mod2)+(dis[i-v[j]]%mod2))%mod2;j++;
            //cout<<i<<'\n';
        }
    }

  //  fr(i,0,n+1)cout<<dis[i]<<" ";

    if(dis[n]==-1)cout<<0;
    else cout<<dis[n];


  
     

    


     

     


    
      




 

return 0;}