#include <bits/stdc++.h>

#define int long long

using namespace std;

#ifdef LOCAL 
#include "/media/brayand/BrayanD/debugger.h"
#else
#define db(...) false
#define dbl(...) false
#define dbg(...) false
#endif

const int MAXN = 2e5 + 100;

int dp[MAXN*2];

const int MOD = 998244353;

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int N, K;
    cin >> N >> K;

    vector<pair<int,int>> vect;

    vector<int> sum;

    for(int i = 1 ; i <= K ; i++)
    {
    	int a, b;
    	cin >> a >> b;
    	vect.push_back({MAXN-b, MAXN-a});
    	sum.push_back(0);
    }

    dp[MAXN] = 1;

    for(int i = MAXN+1 ; i <= MAXN+N-1 ; i++)
    {
    	for(int x = 0 ; x < K ; x++)
    	{
    		sum[x] = (sum + dp[vect[x].second+1]) % MOD;
    		sum[x] = (sum[x] + MOD - dp[vect[x].first]) % MOD;
    		vect[x].first++;
    		vect[x].second++;

    		dp[i] = (dp[i] + sum[x]) % MOD;
    	}
    }

    cout << dp[MAXN+N-1] << '\n';

    return 0;
}