// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



using ll = long long;

using P = pair<ll, ll>;



const ll MOD = 998244353;

const ll INF = 1ll<<60;



#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)

#define REP(i,n) FOR(i,0,n)

#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) ;

#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;



int dx[4]{0, 1, 0, -1};

int dy[4]{1, 0, -1, 0};



template<int mod> struct Fp {

    long long val;

	

    constexpr Fp(long long v = 0) noexcept : val(v % mod) {

        if (val < 0) val += mod;

    }

    constexpr int getmod() { return mod; }

    constexpr Fp operator - () const noexcept {

        return val ? mod - val : 0;

    }

    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }

    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }

    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }

    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }

    constexpr Fp& operator += (const Fp& r) noexcept {

        val += r.val;

        if (val >= mod) val -= mod;

        return *this;

    }

    constexpr Fp& operator -= (const Fp& r) noexcept {

        val -= r.val;

        if (val < 0) val += mod;

        return *this;

    }

    constexpr Fp& operator *= (const Fp& r) noexcept {

        val = val * r.val % mod;

        return *this;

    }

    constexpr Fp& operator /= (const Fp& r) noexcept {

        long long a = r.val, b = mod, u = 1, v = 0;

        while (b) {

            long long t = a / b;

            a -= t * b; swap(a, b);

            u -= t * v; swap(u, v);

        }

        val = val * u % mod;

        if (val < 0) val += mod;

        return *this;

    }

    constexpr bool operator == (const Fp& r) const noexcept {

        return this->val == r.val;

    }

    constexpr bool operator != (const Fp& r) const noexcept {

        return this->val != r.val;

    }

    friend constexpr ostream& operator << (ostream &os, const Fp<mod>& x) noexcept {

        return os << x.val;

    }

    friend constexpr Fp<mod> modpow(const Fp<mod> &a, long long n) noexcept {

        if (n == 0) return 1;

        auto t = modpow(a, n / 2);

        t = t * t;

        if (n & 1) t = t * a;

        return t;

    }

	friend constexpr Fp<mod> modfac(long long l, long long r) noexcept

	{

		auto res = Fp<mod>(1);

		for (Fp<mod> i = l; i < r; ++i) res *= i;

		return res;

	}

};

using mint = Fp<MOD>;





template <class T>

struct BIT

{

	int N;

	vector<T> bit[2];

	BIT(int n_) {init (n_);}

	void init(int n)

	{

		N = n + 1;

		bit[0].assign(N, 0);

		bit[1].assign(N, 0);

	}



	void add_sub(int p, int i, T x)

	{

		for (int j = i; j < N; j += (j & -j))

			bit[p][j] += x;

	}



	T sum_sub(int p, int i)

	{

		T res{0};

		for (int j = i; j > 0; j -= (j & -j))

			res += bit[p][j];

		return res;

	}



	void add(int l, int r, T x) // [l, r)

	{

		add_sub(0, l, -x*(l-1));

		add_sub(0, r, x*(r-1));

		add_sub(1, l, x);

		add_sub(1, r, -x);

	}



	T sum(int i)

	{

		return sum_sub(0, i) + sum_sub(1, i) * i;

	}



	T query(int l, int r) // [l, r)

	{

		return sum(r-1) - sum(l-1);

	}



	int lower_bound(T w)

	{

		if (w <= 0)

		{

			return 0;

		}

		else

		{

			int x = 0, r = 1;

			while (r < N) r = r << 1;

			for (int len = r; len > 0; len = len >> 1)

			{

				ll now = x + len;

				if (now < N && bit[now] < w)

				{

					w -= bit[now];

					x += len;

				}

			}

			return x + 1; // 1-indexed

		}

	}

};



int main(int argc, char **argv)

{

	ios_base::sync_with_stdio(false);

	cin.tie(NULL);



	ll N, K; cin >> N >> K;

	vector<ll> L(K), R(K);

	REP(i, K) cin >> L[i] >> R[i], R[i]++;



	BIT<mint> bit(100000*5);

	bit.add(1, 2, (mint)1);

	for (ll s = 1; s < N; ++s)

	{

		mint t = bit.query(s, s+1);

		DEBUG(t);

		REP(i, K)

		{

			bit.add(s+L[i], s+R[i], t);

		}

	}



	std::cout << bit.query(N, N+1) << std::endl;

	return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



using ll = long long;

using P = pair<ll, ll>;



const ll MOD = 998244353;

const ll INF = 1ll<<60;



#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)

#define REP(i,n) FOR(i,0,n)

#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) ;



int dx[4]{0, 1, 0, -1};

int dy[4]{1, 0, -1, 0};



template<int mod> struct Fp {

    long long val;

	

    constexpr Fp(long long v = 0) noexcept : val(v % mod) {

        if (val < 0) val += mod;

    }

    constexpr int getmod() { return mod; }

    constexpr Fp operator - () const noexcept {

        return val ? mod - val : 0;

    }

    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }

    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }

    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }

    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }

    constexpr Fp& operator += (const Fp& r) noexcept {

        val += r.val;

        if (val >= mod) val -= mod;

        return *this;

    }

    constexpr Fp& operator -= (const Fp& r) noexcept {

        val -= r.val;

        if (val < 0) val += mod;

        return *this;

    }

    constexpr Fp& operator *= (const Fp& r) noexcept {

        val = val * r.val % mod;

        return *this;

    }

    constexpr Fp& operator /= (const Fp& r) noexcept {

        long long a = r.val, b = mod, u = 1, v = 0;

        while (b) {

            long long t = a / b;

            a -= t * b; swap(a, b);

            u -= t * v; swap(u, v);

        }

        val = val * u % mod;

        if (val < 0) val += mod;

        return *this;

    }

    constexpr bool operator == (const Fp& r) const noexcept {

        return this->val == r.val;

    }

    constexpr bool operator != (const Fp& r) const noexcept {

        return this->val != r.val;

    }

    friend constexpr ostream& operator << (ostream &os, const Fp<mod>& x) noexcept {

        return os << x.val;

    }

    friend constexpr Fp<mod> modpow(const Fp<mod> &a, long long n) noexcept {

        if (n == 0) return 1;

        auto t = modpow(a, n / 2);

        t = t * t;

        if (n & 1) t = t * a;

        return t;

    }

	friend constexpr Fp<mod> modfac(long long l, long long r) noexcept

	{

		auto res = Fp<mod>(1);

		for (Fp<mod> i = l; i < r; ++i) res *= i;

		return res;

	}

};

using mint = Fp<MOD>;





template <class T>

struct BIT

{

	int N;

	vector<T> bit[2];

	BIT(int n_) {init (n_);}

	void init(int n)

	{

		N = n + 1;

		bit[0].assign(N, 0);

		bit[1].assign(N, 0);

	}



	void add_sub(int p, int i, T x)

	{

		for (int j = i; j < N; j += (j & -j))

			(bit[p][j] += x) %= MOD;

	}



	T sum_sub(int p, int i)

	{

		T res{0};

		for (int j = i; j > 0; j -= (j & -j))

			(res += bit[p][j]) %= MOD;

		return res;

	}



	void add(int l, int r, T x) // [l, r)

	{

		add_sub(0, l, -x*(l-1));

		add_sub(0, r, x*(r-1));

		add_sub(1, l, x);

		add_sub(1, r, -x);

	}



	T sum(int i)

	{

		ll res = (sum_sub(1, i) * i) % MOD;

		return (res + sum_sub(0, i)) % MOD;

	}



	T query(int l, int r) // [l, r)

	{

		return (sum(r-1) - sum(l-1) + MOD) % MOD;

	}



	int lower_bound(T w)

	{

		if (w <= 0)

		{

			return 0;

		}

		else

		{

			int x = 0, r = 1;

			while (r < N) r = r << 1;

			for (int len = r; len > 0; len = len >> 1)

			{

				ll now = x + len;

				if (now < N && bit[now] < w)

				{

					w -= bit[now];

					x += len;

				}

			}

			return x + 1; // 1-indexed

		}

	}

};



int main(int argc, char **argv)

{

	ios_base::sync_with_stdio(false);

	cin.tie(NULL);



	ll N, K; cin >> N >> K;

	vector<ll> L(K), R(K);

	REP(i, K) cin >> L[i] >> R[i], R[i]++;



	BIT<ll> bit(100000*2+10);

	bit.add(1, 2, 1);

	for (ll s = 1; s < N; ++s)

	{

		ll t = bit.query(s, s+1);

		DEBUG(t);

		REP(i, K)

		{

			bit.add(min(N+1, s+L[i]), min(N+1, s+R[i]), t);

		}

	}



	std::cout << bit.query(N, N+1) << std::endl;

	return 0;

}


// Fastest known solution for this problem: