#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define int long long

#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

using namespace std;

using P = std::pair<int, int>;
using ll = long long;
using ld = double;

using bint = boost::multiprecision::cpp_int;


template<typename T, typename U>
std::istream& operator>>(std::istream& in, std::pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

const int MOD = 998244353;

template<int64_t MOD>
class ModInt {
	typedef int64_t T;
	T x;

  public:
	ModInt(T value) {
		if (value < 0) value = (MOD - (-value) % MOD);
		x = value % MOD;
	}

	ModInt operator-() const {
		return ModInt(-x);
	}

	ModInt& operator+=(const ModInt& p) {
		if ((x += p.get()) >= MOD) x -= MOD;
		return *this;
	}

	ModInt& operator-=(const ModInt& p) {
		if ((x += MOD - p.get()) >= MOD) x -= MOD;
		return *this;
	}

	ModInt& operator*=(const ModInt& p) {
		x = x * p.get() % MOD;
		return *this;
	}

	ModInt& operator/=(const ModInt& p) {
		*this *= p.inverse();
		return *this;
	}

	ModInt& operator+=(const T& p) {
		return *this += ModInt(p);
	}

	ModInt& operator-=(const T& p) {
		return *this -= ModInt(p);
	}

	ModInt& operator*=(const T& p) {
		return *this *= ModInt(p);
	}

	ModInt& operator/=(const T& p) {
		return *this /= ModInt(p);
	}

	ModInt operator+(const ModInt& p) const {
		return ModInt(*this) += p;
	}

	ModInt operator-(const ModInt& p) const {
		return ModInt(*this) -= p;
	}

	ModInt operator*(const ModInt& p) const {
		return ModInt(*this) *= p;
	}

	ModInt operator/(const ModInt& p) const {
		return ModInt(*this) /= p;
	}

	ModInt operator+(const T& p) const {
		return ModInt(*this) += p;
	}

	ModInt operator-(const T& p) const {
		return ModInt(*this) -= p;
	}

	ModInt operator*(const T& p) const {
		return ModInt(*this) *= p;
	}

	ModInt operator/(const T& p) const {
		return ModInt(*this) /= p;
	}

	bool operator==(const ModInt& p) const {
		return x == p.get();
	}

	bool operator!=(const ModInt& p) const {
		return x != p.get();
	}

	bool operator==(const T& p) const {
		return x == ModInt(p);
	}

	bool operator!=(const T& p) const{
		return x != ModInt(p);
	}

	ModInt inverse() const {
		int a = x, b = MOD, u = 1, v = 0;
		while (b) {
			int t = a / b;
			a -= t * b;
			u -= t * v;
			swap(a, b);
			swap(u, v);
		}
		return ModInt(u);
	}

	T get() const{
		return x;
	}

	friend ostream& operator<<(ostream& out,const ModInt& value){
	    out<<value.x;
	    return out;
	}
};

// https://twitter.com/vane11ope ←フォローしましょう
// (ノ)>◡<(ヾ)ﾓﾁﾓﾁ
signed main(signed argc, char* argv[]) {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    int n,k;
    cin>>n>>k;
    vector<P> in(k);
    rep(i,k)cin>>in[i].first>>in[i].second;
    vector<ModInt<MOD>> mp(n,0);
    mp[0]=1;
    mp[1]=-1;
    rep(i,n){
        if(i)mp[i]+=mp[i-1];
        rep(j,k){
            if(i+in[j].first<n){
                mp[i+in[j].first]+=mp[i];
            }
            if(i+in[j].second+1<n){
                mp[i+in[j].second+1]-=mp[i];
            }
        }
    }
    cout<<mp[n-1]<<endl;
}


Measured memory_bytes: 4764