#include using namespace std; // #include // using namespace atcoder; /* alias */ using ull = unsigned long long; using ll = long long; using pii = pair; using pll = pair; using vi = vector; using vll = vector; using vd = vector; using vs = vector; using vb = vector; using vpii = vector>; using vpll = vector>; using vvi = vector>; using vvll = vector>; using vvd = vector>; using vvs = vector>; using vvb = vector>; template using min_priority_queue = priority_queue, greater>; /* define */ #define MOD 998244353 // #define MOD 1000000007 #define INF (1LL << 60) #define elif else if #define pb push_back #define pf push_front #define fi first #define se second #define all(obj) (obj).begin(), (obj).end() #define YESNO(bool) cout << (bool ? "YES\n" : "NO\n") #define YesNo(bool) cout << (bool ? "Yes\n" : "No\n") #define yesno(bool) cout << (bool ? "yes\n" : "no\n") template bool chmax(T &a, const T &b) {if(a bool chmin(T &a, const T &b) {if(b= 0; i--) #define rrepd(i, n) for(ll i = (n); i >= 1; i--) #define fore(i, a) for(auto &i: a) /* vector */ template T vmax(vector &array){ T ret = array[0]; for(T a: array) chmax(ret, a); return ret; } template T vmin(vector &array){ T ret = array[0]; for(T a: array) chmin(ret, a); return ret; } template T sum(vector &array){ T ret = 0; for(T a:array) ret += a; return ret; } template void list_set(vector &array){ sort(all(array)); array.erase(unique(all(array)),array.end()); } template int bisect_left(vector &array, T key){ return lower_bound(all(array),key) - array.begin(); } template int bisect_right(vector &array, T key){ return upper_bound(all(array),key) - array.begin(); } /* string */ ll string_to_ll(string n){ ll ret = 0, k = 1; while(n.length() > 0){ ret += k * (n.back() - '0'); n.pop_back(); k *= 10; } return ret; } string ll_to_string(ll n){ string ret = ""; while(n > 0){ ret.pb((n % 10) + '0'); n /= 10; } reverse(all(ret)); return ret; } struct popopo{ popopo(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(15); }; } popopoppo; // n = 1,...,N に対して、n % A < B を満たすものの数 ll Count_of_n_mod_A_less_than_B(ll N, ll A, ll B){ return N / A * min(A, B) + min(N % A, B - 1); } /* IN/OUT */ int scan() { return getchar(); } void scan(int &a) { cin >> a; } void scan(long long &a) { cin >> a; } void scan(char &a) { cin >> a; } void scan(double &a) { cin >> a; } void scan(string &a) { cin >> a; } template void scan(pair &p) { scan(p.first), scan(p.second); } template void scan(vector &); template void scan(vector &a) { for(auto &i : a) scan(i); } void IN(){} template void IN(Head& head, Tail &...tail){ scan(head); IN(tail...); } #define INT(...) int __VA_ARGS__; IN(__VA_ARGS__) #define LL(...) ll __VA_ARGS__; IN(__VA_ARGS__) #define STR(...) string __VA_ARGS__; IN(__VA_ARGS__) #define VEC(type, name, size) vector name(size); IN(name) #define VECS(type, name, size) vector name(size + 1); for(int i = 1; i <= size; i++) scan(name[i]) void OUT(){ cout << "\n"; } template void output(T a){ cout << a; } template void output(vector v){ for(int i = 0; i < v.size(); i++) cout << v[i] << (i == v.size() - 1 ? "" : " "); } template void OUT(const Head &head, const Tail &...tail) { output(head); if(sizeof...(tail)) cout << " "; OUT(tail...); } void FLASH(){ cout << endl; } template void FLASH(const Head &head, const Tail &...tail) { output(head); if(sizeof...(tail)) cout << " "; FLASH(tail...); } template struct StaticModint{ using mint = StaticModint; public: static constexpr int mod() { return m; } static mint raw(int v) { mint x; x._v = v; return x; } StaticModint() : _v(0) {} template StaticModint(T v) { long long x = (long long)(v % (long long)(umod())); if (x < 0) x += umod(); _v = (unsigned int)(x); } unsigned int val() const { return _v; } mint& operator++() { _v++; if (_v == umod()) _v = 0; return *this; } mint& operator--() { if (_v == 0) _v = umod(); _v--; return *this; } mint operator++(int) { mint result = *this; ++*this; return result; } mint operator--(int) { mint result = *this; --*this; return result; } mint& operator+=(const mint& rhs) { _v += rhs._v; if (_v >= umod()) _v -= umod(); return *this; } mint& operator-=(const mint& rhs) { _v -= rhs._v; if (_v >= umod()) _v += umod(); return *this; } mint& operator*=(const mint& rhs) { unsigned long long z = _v; z *= rhs._v; _v = (unsigned int)(z % umod()); return *this; } mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); } mint operator+() const { return *this; } mint operator-() const { return mint() - *this; } mint pow(long long n) const { assert(0 <= n); mint x = *this, r = 1; while (n) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } mint inv() const { assert(_v); return pow(umod() - 2); } friend mint operator+(const mint& lhs, const mint& rhs) { return mint(lhs) += rhs;} friend mint operator-(const mint& lhs, const mint& rhs) { return mint(lhs) -= rhs; } friend mint operator*(const mint& lhs, const mint& rhs) { return mint(lhs) *= rhs; } friend mint operator/(const mint& lhs, const mint& rhs) { return mint(lhs) /= rhs; } friend bool operator==(const mint& lhs, const mint& rhs) { return lhs._v == rhs._v; } friend bool operator!=(const mint& lhs, const mint& rhs) { return lhs._v != rhs._v; } friend ostream &operator<<(ostream &os, mint x) { os << x.val(); return (os); } private: unsigned int _v; static constexpr unsigned int umod() { return m; } }; using Modint998244353 = StaticModint<998244353>; using Modint1000000007 = StaticModint<1000000007>; using Mint = Modint998244353; template struct Enumeration{ public: Enumeration(int sz = 0) { update(sz); } T fact(int k) { update(k); return _fact[k]; } T finv(int k) { update(k); return _finv[k]; } T inv(int k) { update(k); return _inv[k]; } T nPk(int n, int k) { if(k < 0 || n < k) return 0; return fact(n) * finv(n - k); } T nCk(int n, int k) { if(k < 0 || n < k) return 0; return fact(n) * finv(k) * finv(n - k); } T nHk(int n, int k) { if(n < 0 || k < 0) return 0; if(n == 0) return 1; else return nCk(n + k - 1, k); } T Catalan(int n){ return nCk(2*n, n) - nCk(2*n, n-1); } private: vector _fact, _finv, _inv; void update(int sz) { if(_fact.size() < sz + 1){ int pre_sz = max(1, (int)_fact.size()); _fact.resize(sz + 1, T(1)); _finv.resize(sz + 1, T(1)); _inv.resize(sz + 1, T(1)); for(int i = pre_sz; i <= (int)sz; i++) { _fact[i] = _fact[i - 1] * T(i); } _finv[sz] = T(1) / _fact[sz]; for(int i = (int)sz - 1; i >= pre_sz; i--) { _finv[i] = _finv[i + 1] * T(i + 1); } for(int i = pre_sz; i <= (int)sz; i++) { _inv[i] = _finv[i] * _fact[i - 1]; } } } }; template struct Segtree { public: using S = typename M::T; Segtree() : Segtree(0) {} Segtree(int n) : Segtree(vector (n, M::e())) {} Segtree(const vector &v) : n(int(v.size())) { while((1 << log) < n) log++; size = 1 << log; d = vector (2 * size, M::e()); for(int i = 0; i < n; i++) d[size + i] = v[i]; for(int i = size- 1; i >= 1; i--) update(i); } void set(int p, S x){ assert(0 <= p && p < n); p += size; d[p] = x; for(int i = 1; i <= log; i++) update(p >> i); } S get(int p){ assert(0 <= p && p < n); return d[p + size]; } S prod(int l, int r){ assert(0 <= l && l <= r && r <= n); S sml = M::e(), smr = M::e(); l += size; r += size; while(l < r){ if(l & 1) sml = M::op(sml, d[l++]); if(r & 1) smr = M::op(d[--r], smr); l >>= 1; r >>= 1; } return M::op(sml, smr); } S all_prod(){ return d[1]; } private: int n, size, log = 0; vector d; void update(int k){ d[k] = M::op(d[k * 2], d[k * 2 + 1]); } }; struct Add_M { using T = long long; static T e() { return 0; } static T op(T x, T y) { return x + y; } }; int main() { LL(N, M); vll P(M), K(M); vll T(N + 1, -1); rep(i, M) { LL(p, k); P[i] = p; K[i] = k; T[k] = p; } Enumeration enu(101010); auto f = [&](ll n) -> Mint { Mint res = enu.fact(n); res *= Mint(n) * Mint(n - 1) / Mint(4); return res; }; Mint base = f(N - M); set sP; for (auto s : P) sP.insert(s); Segtree seg(N + 1); for (int i = 1; i <= N; i++) { if (sP.find(i) == sP.end()) { seg.set(i, 1); } } Mint add = 0; ll n = N - M; ll hole = 0; for (int i = 1; i <= N; i++) { if (T[i] != -1) { ll big = seg.prod(T[i], N + 1); ll sml = n - big; Mint u = enu.fact(n - sml); // OUT(hole); add += u; // OUT(u); } else { hole++; } } OUT(base + add); }