#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back

const int M= 998244353;

int32_t main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k,l,r;
    cin>>n>>k;
    vector<int>s;
    map<int,int>mp;
    for(int i=0;i<k;i++){
        cin>>l>>r;
        for(int i=l;i<=r;i++){
            if(mp[i]==0)
            s.pb(i);
            mp[i]++;
        }
    }
    int dp[n+1]={0};
    dp[1]=1;
    for(int i=2;i<=n;i++){
        for(auto it:s){
            if(i-it>=1)
            dp[i]+=(dp[i-it]%M);
        }
    }
    cout<<(dp[n]+M)%M;
    
    return 0;
}