#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using namespace std;
const ll mod = 998244353;

int main(){
	int N, K;
	cin >> N >> K;
	int L[K], R[K];
	rep(i,K) cin >> L[i] >> R[i];
	
	vector<ll> dp(2*N+5);
	dp[0] = 1;
	dp[1] = -1;
	rep(i,N) {
		rep(j,K) {
			dp[i+L[j]] += dp[i];
			dp[i+L[j]] = (dp[i+L[j]]+mod)%mod;
			dp[i+R[j]+1] -= dp[i];
		}
		dp[i+1] += dp[i];
		dp[i+1] = (dp[i+1]+mod)%mod;
	}	
	cout << dp[N-1] << endl;

	return 0;
}
