#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T = double>
using point = complex<T>; // 2D point only

using ll = long long;
using ull = unsigned long long;

using ii = pair<int,int>;
using iii = pair<int, ii>;
using ii_i = pair<ii, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using viii = vector<iii>;
template <typename T = int>
using lim = numeric_limits<T>;

#ifdef _DEBUG
#define debug_text(...) printf(__VA_ARGS__)
#else
#define debug_text(...) /* --- NOTHING --- */
#endif

#define re real()
#define im imag()
#define fi first
#define se second
#define sz(v) (v).size()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

// OST
template <typename T>
using ordered_set = __gnu_pbds::tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// from: https://codeforces.com/blog/entry/62393
// struct custom_hash {
// 	static uint64_t splitmix64(uint64_t x) {
// 		// http://xorshift.di.unimi.it/splitmix64.c
// 		x += 0x9e3779b97f4a7c15;
// 		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
// 		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
// 		return x ^ (x >> 31);
// 	}

// 	size_t operator()(uint64_t x) const {
// 		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
// 		return splitmix64(x + FIXED_RANDOM);
// 	}
// };

const int INF = ~(1<<31);
const ll LINF = (1LL << 60);
const long double EPS = 1e-9;
const long double PI = acos(-1);

const int N = 400005;
const int M = 1 << 19;
const ll MOD = 998244353;
const int MOD2 = 1e9+9;
const int IMAX = 1e9+7;
const ll LMOD = 1LL << 59;
const ll LMAX = 1e18+7;
const ll P = 131;
const ll P2 = 151;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};
const int dx8[8] = {-1,-1,-1,0,0,1,1,1};
const int dy8[8] = {-1,0,1,-1,1,-1,0,1};

template <typename T> struct bit {
    const int n;
    vector<T> t;
    bit(int n) : n(n), t(n + 1) {}
    void add(int i, T value) {
        for(int j = i; j <= n; j += j & -j) {
            (t[j] += value) %= MOD;
        }
    }
    T sum(int i) {
        T res = 0;
        for(int j = i; j > 0; j -= j & -j) {
            (res += t[j]) %= MOD;
        }
        return res;
    }
    T sum(int L, int R) {
        return (sum(R) - sum(L - 1)+5LL*MOD)%MOD;
    }
};

template <typename T> struct range_bit {
    bit<T> t;
    range_bit(int n) : t(bit<T>(n)) {}
    void add(int L, int R, T value) {
        t.add(L, value);
        t.add(R + 1, -value);
    }
    T get(int i) {
        return t.sum(i);
    }
};

ll n, k;
pair<ll,ll> moves[15];

void solution() {
	cin >> n >> k;
	for (int i = 0; i < k; ++i) {
		cin >> moves[i].fi >> moves[i].se;
	}

	range_bit<ll> b(2*n+1);
	b.add(1,1,1);

	for (int i = 1; i < n; ++i) {
		ll tmp = b.get(i);
		for (int j = 0; j < k; ++j) {
			b.add(i+moves[j].fi, i+moves[j].se, tmp);
		}
	}

	cout << b.get(n) << endl;
}

void pregen() {
	
}

void prepare() {
	
}

int main () {
	ios_base::sync_with_stdio(false); cin.tie(0); // cout.tie(0);
	// cout.precision(2); cout << fixed;

	int T = 1;
	// cin >> T;
	pregen();
	for (int i = 1; i <= T; ++i) {
		prepare();
		solution();
	}

	return 0;
}