// D - Leaping Tak
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using ll = long long;
#define rp(i,s,e) for(int i=(int)(s);i<(int)(e);++i)

int main(){
	int N, K; cin>>N>>K;
	vi F(N+2, 0), S;
	rp(i,0,K){
		int l, r; cin>>l>>r;
		F[l]++;
		F[r+1]--;
	}
	rp(i,0,N+1){
		if(F[i] > 0) S.push_back(i);
		F[i+1] += F[i];
	}

	// for(auto s:S){
	// 	cout<<s<<" ";
	// }
	// puts("");

	int MOD = 998'244'353;
	vector<ll> dp(N+1, 0);
	dp[1] = 1;
	rp(i,1,N+1){
		for(auto s:S){
			if(i+s <= N){
				dp[i+s] += dp[i];
				dp[i+s] %= MOD;
			}
		}
	}

	cout<< (dp[N] + MOD) % MOD <<endl;
}
