#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define eb emplace_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define cinarr(A,len) for(int i=0;i<len;i++){cin>>A[i];}
#define coutarr(A,len) for(int i=0;i<len;i++){cout<<A[i]<<' ';}cout<<endl
#define coutin(V) for(auto& i : V){cout << i << ' ';}cout<<endl // for vect and set
#define coutmap(U) for(auto& i : U){cout << i.first << "->" << i.second << ", ";}cout<<endl // for map
#define deb(x) cerr << #x << '\t' << x << endl
const int imax = numeric_limits<int>::max(), imin = numeric_limits<int>::min();
const long long	lmax = numeric_limits<long long>::max(), lmin = numeric_limits<long long>::min();
/*========================================================================*/
/* strategi/note:



/================================*/



bool Svd=0;
void solve(){Svd=1;
    // dp coin problem saja
    int n,k;
    cin >> n >> k;
    // non intersecting: bagus!
    pair<int,int> d[k];
    int l,r;
    for(int i = 0; i<k; i++){
        cin >> l >> r;
        d[i] = {l,r};
    }
    sort(d,d+k);
    int dp[n] = {0};
    dp[0] = 1;
    for(int i = 1; i<n; i++){
        bool breaker = false;
        for(auto& D : d){
            for(int j = D.first; j<=D.second; j++){
                if(i-j >= 0){
                    //cout << i << ' ' << j << endl;
                    dp[i] = (dp[i] + dp[i-j])%998244353;
                }
                else{
                    breaker = true;
                    break; // sudah jelas kan sorted l,r nya semakin nambah jnya
                }
            }
            if(breaker){
                break;
            }
        }
    }
    cout << dp[n-1] << endl;
}


/*========================================================================*/

int main(){ios_base::sync_with_stdio(0);cin.tie(0);
//cout<<fixed<<setprecision( ); // iomanip **

 solve();
 //int t;cin>>t;while(t--){solve();}

if(!Svd)cout<<"solve() function blm dipanggil!"<<endl;
//cout.flush(); cin.get();
return 0;
}
