#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define reps(i, s, n) for(int i = (s); i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, s, n) for(int i = (n) - 1; i >= (s); i--)
#define INF ~(1 << 31)
#define INFL ~(1LL << 63)
#define mod 998244353LL

int main()
{
    int n, k;
    cin >> n >> k;
    vector<pair<int, int>> d(k);
    rep(i, k){
        cin >> d[i].first >> d[i].second;
    }

    vector<ll> dp(n+1);
    dp[1] = 1;
    reps(i, 2, n+1){
        rep(j, k){
            int f = i - d[j].first, s = max(i - d[j].second, 1);
            if(f < 1) continue;
            else if(s == 1) dp[i] = (dp[i] + dp[f]) % mod;
            else dp[i] = (dp[i] - dp[s-1] + dp[f]) % mod;
        }
        dp[i] = (dp[i] + dp[i-1]) % mod;
    }
    if(dp[i] < dp[i-1]) dp[i] += mod;
    cout << dp[n] - dp[n-1] << endl;
}