#include<bits/stdc++.h>
#define for_int(i,a,b) for(int i=(a);i<=(b);++i)
#define rep_int(i,a,b) for(int i=(a);i>=(b);--i)
#define for_ll(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep_ll(i,a,b) for(ll i=(a);i>=(b);--i)
#define IOS ios::sync_with_stdio(false);
#define ull unsigned long long
#define ll long long
#define db double
#define HPMAX 1005
#define KMP_MAX 1005
#define prime_MAX 1000005
#define quick_pow_mod 1000000007
#define PII pair<int,int>
const int factor_N = 10000005;
const int tree_arr_N = 1000005;
using namespace std;
/*
	1.注意边界情况
	2.优先考虑时间复杂度
!!! 3.求最大值时，答案应至多初始化为INT_MIN；求最小值时，答案应至少初始化为INT_MAX
	4.遇事不决先暴力
	5.代码要写简洁
*/
//快读
int read() {
	char c = getchar();
	int x = 0, f = 1;
	for (; !isdigit(c); c = getchar())
		if (c == '-') f = -1;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;
	return x * f;
}
const int mod = 998244353;
int n, k, l, r;
int main() {
	n = read(); k = read();
	vector<int>dp(n + 1, 0), a;
	map<int, bool>mp;
	while (k--) {
		l = read(); r = read();
		while (l <= r) {
			if (mp[l] != true) a.push_back(l), mp[l] = true;
			l++;
		}
	}
	sort(a.begin(), a.end());
	dp[1] = 1;
	for (int i = 2; i <= n; ++i) {
		for (auto step : a) {
			if (step >= i) break;
			dp[i] = (dp[i] + dp[i - step]) % mod;
		}
	}
	cout << dp[n] << endl;
	return 0;
}