#include<bits/stdc++.h>
#include<atcoder/modint>
using namespace std;
using ll = long long;
const ll mod = 998244353;

template<class M> class DualSegmentTree {
public:
	using T = typename M::value_type;
private:
	int m;
	int n;
	vector<T> data;

	void rec(int l, int r, int node, int node_l, int node_r, const T& val) {
		if(node_r <= l || node_l >= r)return;
		if(node_l >= l && node_r <= r){data[node] = M::upd(data[node], val); return;}
		int mid = (node_l + node_r) / 2;
		rec(l, r, node * 2, node_l, mid, val);
		rec(l, r, node * 2 + 1, mid, node_r,val);
	}

public:
	DualSegmentTree(vector<T> a) {
		m = a.size();
		for(n = 1; n < (int)a.size(); n <<= 1);
		data.resize(n<<1, M::id);
		for(int i = 0; i < (int)a.size(); i++)data[i + n] = a[i];
	}
 
	void update(int l, int r, T val) {
		rec(l, r, 1, 0, n, val);
	}
 
	T get(int index) {
		T ret = data[index += n];
		while(index /= 2) {
			ret = M::op(ret, data[index]);
		}
		return ret;
	}
 
	T operator[] (int i){
		return data[i + n];
	}
};

//区間加算・一点取得
template<class T> class RAQ { public:
using value_type = T;
	static T op(T l, T r){ return (l + r) % mod; }
	static T upd(T node, T val){ return (node + val) % mod; }
	static constexpr T id = 0;
};template <class T> constexpr T RAQ<T>::id;

int main()
{
	int n, k; cin >> n >> k;
	vector<ll> a(n);
	vector<pair<int,int>> sg(k);
	for(int i = 0; i < k; i++)cin >> sg[i].first >> sg[i].second, sg[i].second++;
	a[0] = 1;
	DualSegmentTree<RAQ<ll>> tree(a);

	for(int i = 0; i < n; i++) {
		ll cur = tree.get(i) % mod;
		for(int j = 0; j < k; j++) {
			tree.update(min(n, i + sg[j].first), min(n, i + sg[j].second), cur);
		}
	}
	cout << tree.get(n - 1)%mod << endl;

}