#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)

using namespace std;

template<int64_t M = 1000000007>
class ModInt {
public:
	ModInt() : val_(0) {};

	ModInt(int64_t val) {
		this->val_ = val;
		this->val_ %= M;
		while (this->val_ >= M) this->val_ -= M;
		while (this->val_ < 0)  this->val_ += M;
	}

	operator int64_t() const {
		return this->val_;
	}

	ModInt& operator += (int64_t val) {
		this->val_ += val;
		this->val_ %= M;
		while (this->val_ >= M) this->val_ -= M;
		while (this->val_ < 0) this->val_ += M;

		return *this;
	}

	ModInt& operator -= (int64_t val) {
		this->val_ -= val;
		this->val_ %= M;
		while (this->val_ >= M) this->val_ -= M;
		while (this->val_ < 0) this->val_ += M;

		return *this;
	}

	ModInt& operator *= (int64_t val) {
		this->val_ *= val;
		this->val_ %= M;

		return *this;
	}

	ModInt& operator /= (int64_t val) {
		ModInt v = ModInt::pow(val, M - 2);
		*this *= v;

		return *this;
	}

	ModInt operator + (int64_t v) const {
		ModInt ret = *this;
		return (ret += v);
	}

	ModInt operator - (int64_t v) const {
		ModInt ret = *this;
		return (ret -= v);
	}

	ModInt operator * (int64_t v) const {
		ModInt ret = *this;
		return (ret *= v);
	}

	ModInt operator / (int64_t v) const {
		ModInt ret = *this;
		return (ret /= v);
	}

	static ModInt pow(ModInt n, int64_t m) {
		if (m == 0) {
			ModInt ret(1);
			return ret;
		}
		if (m == 1) {
			return n;
		}

		ModInt v = pow(n, m / 2);
		ModInt ret = v * v;
		if (m & 1) {
			ret *= n;
		}
		return ret;
	}

	ostream& operator << (ostream& out) {
		out << this->val_;
		return out;
	}

private:
	int64_t val_;
};


template <typename T>
struct SegT {
	int n;
	vector<T> dat, lazy;
	SegT(int n_) : n(), dat(n_ * 4, 0), lazy(n_ * 4, 0) {
		int x = 1;
		while (n_ > x) x *= 2;
		n = x;
	}
	/* lazy eval */
	void eval(int k) {
		if (lazy[k] == 0) return;  // 更新するものが無ければ終了
		if (k < n - 1) {             // 葉でなければ子に伝搬
			lazy[k * 2 + 1] += lazy[k];
			lazy[k * 2 + 2] += lazy[k];
		}
		// 自身を更新
		dat[k] += lazy[k];
		lazy[k] = 0;
	}
	void update(int a, int b, T x, int k, int l, int r) {
		eval(k);
		if (a <= l && r <= b) {  // 完全に内側の時
			lazy[k] += x;
			eval(k);
		}
		else if (a < r && l < b) {                     // 一部区間が被る時
			update(a, b, x, k * 2 + 1, l, (l + r) / 2);  // 左の子
			update(a, b, x, k * 2 + 2, (l + r) / 2, r);  // 右の子
			dat[k] = dat[k * 2 + 1] + dat[k * 2 + 2];
		}
	}
	void update(int a, int b, T x) { update(a, b, x, 0, 0, n); }
	T query_sub(int a, int b, int k, int l, int r) {
		eval(k);
		if (r <= a || b <= l) {  // 完全に外側の時
			return 0;
		}
		else if (a <= l && r <= b) {  // 完全に内側の時
			return dat[k];
		}
		else {  // 一部区間が被る時
			T vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
			T vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
			return vl + vr;
		}
	}
	T query(int a, int b) { return query_sub(a, b, 0, 0, n); }
	/* debug */
	inline T operator[](int a) { return query(a, a + 1); }
	void print() {
		for (int i = 0; i < 2 * n - 1; ++i) {
			cout << (*this)[i];
			if (i != n) cout << ",";
		}
		cout << endl;
	}
};

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n, m; cin >> n >> m;
	vector<pair<int, int>> ps(m);
	for (auto& p : ps) { cin >> p.first >> p.second; }

	SegT<ModInt< 998244353>> segt(n + 1);

	segt.update(0, 1, 1);
	FOR_LT(i, 0, n - 1) {
		auto v = segt.query(i, i + 1);
		//cout << i << " " << v << endl;
		for (auto p : ps) {
			if (n <= p.first + i) continue;
			if (n <= p.second + i) p.second = n - i - 1;
			segt.update(i + p.first, i + p.second + 1, v);
		}
	}
	cout << segt.query(n - 1, n) << endl;


	return 0;
}


Measured memory_bytes: 15940