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


#define int long long 

const int N = 4e5 + 7, mod = 998244353;

int dp[N], cum[N], L[N], R[N];

int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, k; cin >> n >> k;
	for(int i = 1; i <= k; ++i) cin >> L[i] >> R[i];

	dp[n] = 1;
	for(int i = n - 1; i >= 1; i--) {
		for(int j = 1; j <= k; j++) {
			int l = L[j], r = R[j];
			if(i + l <= n) {
				dp[i] += dp[i + l] + mod - dp[i + r + 1] % mod;
				dp[i] %= mod;
			}
		}
		dp[i] = (dp[i] + dp[i + 1]) % mod;
	}
	cout << (dp[1] + mod - dp[2]) % mod;
}
