#include #include using namespace std; using namespace atcoder; using ll = long long; using mint = modint998244353; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, m, p, k, rem; cin >> n >> m; vector> a(m); vector s2(n + 1, 1); for(int i = 0; i < m; i++){ cin >> p >> k; s2[k]--; a[i] = make_pair(--p, --k); } sort(a.begin(), a.end()); for(int i = 0; i < n; i++) s2[i + 1] += s2[i]; rem = n - m; mint ans, fr, ba, up, down, ten; fenwick_tree fw(n); for(int i = 0; i < m; i++){ tie(p, k) = a[i]; fr = p - i, ba = n - p - (m - i); down = s2[k] - 1, up = s2[n] - s2[k]; ans += fr * up + ba * down; ten += fw.sum(k, n); fw.add(k, 1); } if(rem) ans /= rem; ans += mint(rem) * (rem - 1) / 4 + ten; for(int i = 2; i <= rem; i++) ans *= i; cout << ans.val() << '\n'; }