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

#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
namespace adaptor = boost::adaptors;

// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */

using ll = long long;
using ull = unsigned long long;

ll dp[200010] = {0};

void Main()
{
	ll N, K;
	cin >> N >> K;

	std::vector <ll> S;
	for (ll i = 0; i < K; ++i) {
		ll L, R;
		cin >> L >> R;
		for (ll j = L; j <= R; ++j) {
			S.push_back(j);
		}
	}

	dp[0] = 1;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < (int)S.size(); ++j) {
			if (i + S[j] <= N) {
				dp[i + S[j]] = (dp[i + S[j]] + dp[i]) % 998244353;
			}
		}
	}

	cout << dp[N - 1];
	return;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}