#include<iostream>
#include<vector>
#include<set>

const constexpr auto prime_ = 998'244'353;

int main(){
	std::uint32_t n, k;
	std::cin >> n >> k;

	std::set<std::uint32_t> set_;//steps_
	for( std::uint32_t ki{}; ki < k; ++ki )
	{
		std::uint32_t l_, r_;
		std::cin >> l_ >> r_;
		for( std::uint32_t i{l_};i<=r_;++i )
			set_.emplace( i );
	}

	
	std::vector<std::uint64_t> table_( n + 5 ,0 );
	table_[1] = 1;
	for( std::uint32_t i{ 1 }; i < n; ++i )
	{
		for( auto step_ : set_ )
		{
			if( i + step_ > n )
				break;
//			std::cout <<"["<< i << " " << i + step_ << "]";
			table_[i + step_] += table_[i];
			table_[i + step_] %= prime_;
		}
	}
	
	std::cout << table_[n] << "\n";
	return 0;
}
