#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 1;
const int MOD = 998244353;
vector<ll> steps;

int main(){
	fast;
	ll n, k;
	cin >> n >> k;
	while(k--){
		int a, b;
		cin >> a >> b;
		for(int i = a; i <= b; ++i)
			steps.push_back(i);
	}
	sort(steps.begin(), steps.end());
	ll dp[n + 1] = {0};
	dp[0] = 1;
	for(int i = 1; i < n; ++i){
		int j = 0;
		while(i - steps[j] >= 0 && j < steps.size()){
			dp[i] = (dp[i] + (((dp[i - steps[j]]) % MOD))%MOD)% MOD;
			++j;
		}
	}
	cout << dp[n - 1];
	cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}
