#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
#define X first;
#define Y second;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
const ll INF = 2e18;
const int inf = 1e9+10;
const int maxN = 2e5 + 10;
const int maxK = 1e4+10;
const int maxD = 15;
const int maxH = 100; 
//const int MOD = 998244353;


template<class data_type>
struct segment_tree
{
	using T = data_type;
	int n;
	vector<T> a;

	using initialize_type = function<void(T&, int)>;
	using merge_type = function<void(T&, const T&, const T&)>;
	using pushdown_type = function<void(T&, int, int, T&, T&)>;
	initialize_type initialize;
	merge_type merge;
	pushdown_type pushdown;

	void clear(int k, int L, int R)
	{
		pushdown(a[k], L, R, a[k << 1], a[k << 1 | 1]);
	}
	void update(int k)
	{
		merge(a[k], a[k << 1], a[k << 1 | 1]);
	}
	void build(int k, int L, int R)
	{
		if (L == R)
		{
			initialize(a[k], L);
			return;
		}
		int m = (L + R) >> 1;
		build(k << 1, L, m);
		build(k << 1 | 1, m + 1, R);
		update(k);
	}
	segment_tree(int n, const initialize_type& initialize, const merge_type& merge, const pushdown_type& pushdown)
	{
		assert(n >= 1);
		this->n = n;
		this->initialize = initialize;
		this->merge = merge;
		this->pushdown = pushdown;
		a = vector<T>(4 * n + 1);
		build(1, 1, n);
	}

	using modifier_type = function<void(T&, int, int)>;
	void modify(int k, int L, int R, int x, int y, const modifier_type& modifier)
	{
		if (L == x && R == y)
		{
			modifier(a[k], L, R);
			return;
		}
		int m = (L + R) >> 1;
		clear(k, L, R);
		if (y <= m)
			modify(k << 1, L, m, x, y, modifier);
		else if (x > m)
			modify(k << 1 | 1, m + 1, R, x, y, modifier);
		else
		{
			modify(k << 1, L, m, x, m, modifier);
			modify(k << 1 | 1, m + 1, R, m + 1, y, modifier);
		}
		update(k);
	}
	void modify(int x, int y, const modifier_type& modifier)
	{
		assert(1 <= x && x <= y && y <= n);
		modify(1, 1, n, x, y, modifier);
	}

	template<class result_type, class convert_type = function<result_type(const T&)>, class calculate_type = function<result_type(const result_type&, const result_type&)>>
	result_type query(int k, int L, int R, int x, int y, const convert_type& convert, const calculate_type& calculate)
	{
		if (L == x && R == y)
			return convert(a[k]);
		int m = (L + R) >> 1;
		clear(k, L, R);
		if (y <= m)
			return query<result_type>(k << 1, L, m, x, y, convert, calculate);
		if (x > m)
			return query<result_type>(k << 1 | 1, m + 1, R, x, y, convert, calculate);
		return calculate(query<result_type>(k << 1, L, m, x, m, convert, calculate), query<result_type>(k << 1 | 1, m + 1, R, m + 1, y, convert, calculate));
	}
	template<class result_type, class convert_type = function<result_type(const T&)>, class calculate_type = function<result_type(const result_type&, const result_type&)>>
	result_type query(int x, int y, const convert_type& convert, const calculate_type& calculate)
	{
		assert(1 <= x && x <= y && y <= n);
		return query<result_type>(1, 1, n, x, y, convert, calculate);
	}

	T query(int x, int y)
	{
		assert(1 <= x && x <= y && y <= n);
		function<T(const T&)> convert = [](const T& it) -> T
		{
			return it;
		};
		function<T(const T&, const T&)> calculate = [&](const T& Lc, const T& Rc) -> T
		{
			T ret;
			merge(ret, Lc, Rc);
			return ret;
		};
		return query<T>(x, y, convert, calculate);
	}

	using checker_type = function<bool(T&, int, int)>;
	int find_first_of(int k, int L, int R, const checker_type& checker)
	{
		if (L == R)
		{
			assert(checker(a[k], L, R));
			return L;
		}
		clear(k, L, R);
		int m = (L + R) / 2;
		if (checker(a[k << 1], L, m))
			return find_first_of(k << 1, L, m, checker);
		else
			return find_first_of(k << 1 | 1, m + 1, R, checker);
	}
	int find_first_of(const checker_type& checker)
	{
		if (!checker(a[1], 1, n)) return n + 1;
		return find_first_of(1, 1, n, checker);
	}

	// find_last_of not checked
	int find_last_of(int k, int L, int R, const checker_type& checker)
	{
		if (L == R)
		{
			assert(checker(a[k], L, R));
			return L;
		}
		clear(k, L, R);
		int m = (L + R) / 2;
		if (checker(a[k << 1 | 1], m + 1, R))
			return find_last_of(k << 1 | 1, m + 1, R);
		else
			return find_last_of(k << 1, L, m);
	}
	int find_last_of(const checker_type& checker)
	{
		if (!checker(a[1], 1, n)) return 0;
		return find_last_of(1, 1, n, checker);
	}
};
const int MOD = 998244353;

struct mod_int {
	int val;

	mod_int(long long v = 0) {
		if (v < 0)
			v = v % MOD + MOD;

		if (v >= MOD)
			v %= MOD;

		val = v;
	}

	static int mod_inv(int a, int m = MOD) {
		// https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Example
		int g = m, r = a, x = 0, y = 1;

		while (r != 0) {
			int q = g / r;
			g %= r; swap(g, r);
			x -= q * y; swap(x, y);
		}

		return x < 0 ? x + m : x;
	}

	explicit operator int() const {
		return val;
	}

	mod_int& operator+=(const mod_int& other) {
		val += other.val;
		if (val >= MOD) val -= MOD;
		return *this;
	}

	mod_int& operator-=(const mod_int& other) {
		val -= other.val;
		if (val < 0) val += MOD;
		return *this;
	}

	static unsigned fast_mod(uint64_t x, unsigned m = MOD) {
		return x % m;
	}

	mod_int& operator*=(const mod_int& other) {
		val = fast_mod((uint64_t)val * other.val);
		return *this;
	}

	mod_int& operator/=(const mod_int& other) {
		return *this *= other.inv();
	}

	friend mod_int operator+(const mod_int& a, const mod_int& b) { return mod_int(a) += b; }
	friend mod_int operator-(const mod_int& a, const mod_int& b) { return mod_int(a) -= b; }
	friend mod_int operator*(const mod_int& a, const mod_int& b) { return mod_int(a) *= b; }
	friend mod_int operator/(const mod_int& a, const mod_int& b) { return mod_int(a) /= b; }

	mod_int& operator++() {
		val = val == MOD - 1 ? 0 : val + 1;
		return *this;
	}

	mod_int& operator--() {
		val = val == 0 ? MOD - 1 : val - 1;
		return *this;
	}

	mod_int operator++(int) { mod_int before = *this; ++* this; return before; }
	mod_int operator--(int) { mod_int before = *this; --* this; return before; }

	mod_int operator-() const {
		return val == 0 ? 0 : MOD - val;
	}

	bool operator==(const mod_int& other) const { return val == other.val; }
	bool operator!=(const mod_int& other) const { return val != other.val; }

	mod_int inv() const {
		return mod_inv(val);
	}

	mod_int pow(long long p) const {
		assert(p >= 0);
		mod_int a = *this, result = 1;

		while (p > 0) {
			if (p & 1)
				result *= a;

			a *= a;
			p >>= 1;
		}

		return result;
	}

	friend ostream& operator<<(ostream& stream, const mod_int& m) {
		return stream << m.val;
	}
};
struct node
{
	mod_int val,tag;
};
int main()
{
	int n,k;
	cin>>n>>k;
	vector<pii> p;
	for(int i=1;i<=k;i++)
	{
		int x,y;
		cin>>x>>y;
		p.push_back({x,y});
	}
	
	auto initialize = [&](node& it, int id) -> void
	{
		it.val = 0; it.tag = 0;
	};
	auto merge = [&](node& it, const node& Lc, const node& Rc) -> void
	{
	  	it.val = (Lc.val + Rc.val); it.tag = 0;
	};
	auto pushdown = [&](node& it, int L, int R, node& Lc, node& Rc) -> void
	{
	    if (it.tag != 0)
	    {
	        int m = (L+R)/2;
	        Lc.val += it.tag*(m-L+1); Lc.tag += it.tag;
	        Rc.val += it.tag*(R-m); Rc.tag += it.tag;
	        it.tag = 0;
	    }
	};
	segment_tree<node> H(n, initialize, merge, pushdown);
	
	H.modify(1, 1, [&](node& it, int L, int R)
	{
	   it.val += 1*(R-L+1);
	   it.tag += 1;
	});
	int m = p.size();
	for(int i=1;i<n;i++)
	{
		node res = H.query(i, i);
		mod_int val = res.val;
		for(int j=0;j<m;j++)
		{
			int x = p[j].first;
			int y = p[j].second;
			x += i;
			y += i;
			y = min(n,y);
			if(x<=y) {
				H.modify(x, y, [&](node& it, int L, int R)
				{
				   it.val += val*(R-L+1);
				   it.tag += val;
				});
			}
			
		}
	}
	node res = H.query(n, n);
	cout<<int(res.val)<<endl;
	return 0;
}

Measured memory_bytes: 9604