#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
#include<cassert>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

/////////////////////////////////////
template <typename T, typename E>

struct lst {
	using F = function<T(T, T)>;//ノードのもつ値同士の演算
	using G = function<T(T, E, ll)>;//ノードへの更新作用(llは区間の長さ)
	using H = function<E(E, E)>;//更新のmerge

	ll n;
	F f;
	G g;
	H h;
	T ti;
	E ei;

	ll size;
	vector<ll> node, lazy;

	lst(ll n0, F f0, G g0, H h0, T ti0, E ei0) {
		n = n0;
		f = f0; g = g0; h = h0; ti = ti0; ei = ei0;

		size = 1;
		while (size < n) {
			size *= 2;
		}

		node.assign(2 * size, ti);
		lazy.assign(2 * size, ei);
	}

	void eval(ll k, ll l, ll r) {//k=[l,r)の評価
		if (lazy[k] != 0) {
			node[k] = g(node[k], lazy[k], (r - l));
		}

		if (k < size) {
			lazy[2 * k] = h(lazy[2 * k], lazy[k]);
			lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]);
		}

		lazy[k] = 0;
	}

	void update_prep(ll a, ll b, E x, ll k, ll l, ll r) {
		eval(k, l, r);

		if (b <= l || r <= a) { return; }

		if (a <= l && r <= b) {
			lazy[k] = h(lazy[k], x);
			eval(k, l, r);
			return;
		}

		update_prep(a, b, x, 2 * k, l, (l + r) / 2);
		update_prep(a, b, x, 2 * k + 1, (l + r) / 2, r);
		node[k] = f(node[2 * k], node[2 * k + 1]);
	}

	void update(ll a, ll b, E x) {//[a,b)の更新
		return update_prep(a, b, x, 1, 1, size + 1);
	}

	T query_prep(ll a, ll b, ll k, ll l, ll r) {

		eval(k, l, r);

		if (b <= l || r <= a) { return ti; }
		if (a <= l && r <= b) { return node[k]; }

		T v1 = query_prep(a, b, 2 * k, l, (l + r) / 2);
		T v2 = query_prep(a, b, 2 * k + 1, (l + r) / 2, r);
		return f(v1, v2);

	}

	T query(ll a, ll b) {
		return query_prep(a, b, 1, 1, size + 1);
	}

};

//////////////////////


int main() {
	ll N, K;
	cin >> N >> K;

	vll L(K + 1), R(K + 1);
	repn(i, K)cin >> L[i] >> R[i];

	vmint dp(N + 1, 0), rdp(N + 1, 0);
	
	dp[1] = 1;
	rdp[1] = 1;
	for(ll i=2;i<=N;i++) {
		repn(j, K) {
			if (i > L[j]) {
				dp[i] += rdp[i - L[j]] - rdp[max(i - R[j] - 1, 0)];
				//cout << dp[i] << endl;
			}
		}
		//cout << i << " " << dp[i] << endl;
		rdp[i] = rdp[i - 1] + dp[i];
	}

	cout << dp[N] << endl;
}

Measured memory_bytes: 6424