#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
 
int main(){
    ll n,k; cin>>n>>k;
    const ll mod = 998244353;
    vector<pair<ll,ll>> s(k);
    rep(i,k) cin>>s[i].first>>s[i].second;
    vector<ll> dp(n+1,0);
    dp[0] = 1;
    dp[1] = -1;
    rep(i,n){
        ll now = dp[i] = (dp[i]%mod+mod)%mod;
        dp[i+1] += now;
 
        rep(j,k){
            ll l = s[j].first;
            ll r = s[j].second;
            if(i+l<n) dp[i+l] += now;
            if(i+r<n) dp[i+r+1] -= now;
        }
    }
    cout << dp[n-1] << endl;
}