#include <bits/stdc++.h>
using namespace std;

#define REP(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ALL(c) c.begin(), c.end()
#define SZ(c) (int) c.size()
#define DBG1(x) cout<<#x<<" = "<<x<<"\n"
#if USE_CP_REDIR
#define CP \
    freopen("input.txt","r", stdin); \
    freopen("output.txt","w", stdout);
#endif

using ll = long long;
using pii = pair<int,int>;

const ll MOD = 998244353;
const int MN = 200'000;
int N, K;
ll DP[MN+100];

ll add(ll a, ll b)
{
    a %= MOD;
    b %= MOD;
    return (a + b) % MOD;
}

ll cnt(int i, const vector<pii>& S)
{
    if(i == N) return 1LL;
    if(i > N) return 0LL;
    
    ll& ans = DP[i];
    if(ans !=  -1) return ans;

    ans = 0LL;
    for(const pii& s: S){
        for(int d = s.first; d <= s.second; d++){
            if(i+d > N) goto fim;
            ans = add(ans, cnt(i+d, S));
        }
    }
    fim:
    return ans;
}

ll cnt2(const vector<pii>& S)
{
    DP[N] = 1;
    for(register int i = N - 1; i > 0; i--){
        for(const pii& s: S){
            for(int d = s.first; d <= s.second; d++){
                if(i + d > N) goto outer;
                    DP[i] = add(DP[i], DP[i+d]);
            }
        }
        outer:;
    }
    return DP[1];
}


int main()
{
ios::sync_with_stdio(false);
#ifdef CP
    CP;
#endif
    cin >> N >> K;
    vector<pii> S(K);
    REP(i,0,K) cin >> S[i].first >> S[i].second;
    memset(DP, 0, sizeof DP);
    sort(ALL(S));
    cout << cnt2(S) << endl;
}