//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define endl '\n'
#define mod 998244353
typedef long long int ll;
using namespace std;
#define MAX 100005
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,k; cin>>n>>k;
    set<ll> st;
    for(int i=1;i<=k;i++){
        ll a,b; cin>>a>>b;
        for(int j=a;j<=b;j++) st.insert(j);
    }
    ll dp[n+3]={0};
     dp[1]=1;
     vector<int> v;
     for(auto i: st) v.push_back(i);
     
     for(int i=2;i<=n;i++){
         for(auto j: v)
         {
             if(i-j>=1) dp[i]=(dp[i]+dp[i-j])%mod;
         }
     }
     cout<<dp[n]%mod<<endl;
    
}