#include using namespace std; typedef long long ll; typedef pair PP; //#define MOD 1000000007 #define MOD 998244353 #define INF 2305843009213693951 //#define INF 810114514 #define PI 3.141592653589 #define setdouble setprecision #define REP(i,n) for(ll i=0;i<(n);++i) #define OREP(i,n) for(ll i=1;i<=(n);++i) #define RREP(i,n) for(ll i=(n)-1;i>=0;--i) #define ALL(v) (v).begin(), (v).end() #define GOODBYE do { cout << "-1" << endl; return 0; } while (false) #define MM <<" "<< #define Endl endl #define debug true #define debug2 false class compress{ /* Copyright (c) 2021 0214sh7 https://github.com/0214sh7/library/ */ private: std::vector E; public: void init(std::vector A){ E.clear(); sort(A.begin(),A.end()); for(int i=0;i A){ init(A); } int size(){ return (int)E.size(); } int value(int x){ if(0<=x && x<(int)E.size()){ return E[x]; }else{ return 0; } } int index(int X){ return (upper_bound(E.begin(),E.end(),X))-E.begin()-1; } }; class Fenwick_tree{ /* Copyright (c) 2021 0214sh7 https://github.com/0214sh7/library/ */ private: std::vector BIT; public: void add(int a,long long w){ for(int x=a;x=0;x=(x&(x+1))-1){ r+=BIT[x]; } return r; } long long inversion(std::vector V){ long long r=0; init(V.size()); for(int i=0;i>=1; } return r; } int main(void){ //cin.tie(nullptr); //ios::sync_with_stdio(false); ll N,M; cin >> N >> M; vector P(M),K(M); REP(i,M){ cin >> P[i] >> K[i]; P[i]--;K[i]--; } vector Y(N,1),Z(N,-1); REP(i,M){ Y[P[i]]=0; Z[K[i]]=P[i]; } vector E = {-INF}; REP(i,N){ if(Y[i]==1)E.push_back(i); } //REP(i,N){cout << Z[i] << " ";}cout << endl; //REP(i,E.size()){cout << E[i] << " ";}cout << endl; vector X; REP(i,N){if(Z[i]!=-1)X.push_back(Z[i]);} compress zaatsu(X); REP(i,X.size()){X[i] = zaatsu.index(X[i]);} //REP(i,X.size()){cout << X[i] << " ";}cout << endl; Fenwick_tree BIT(N); ll Ans = BIT.inversion(X)%MOD; REP(i,N-M){Ans = (Ans*(i+1))%MOD;} //cout << Ans << endl; vector W(N,0); ll sum = 0; REP(i,N){ if(Z[i]!=-1){ auto it = upper_bound(ALL(E),Z[i]);it--; ll u = distance(E.begin(),it); W[Z[i]] = u; sum += N-M-u; } } /*REP(i,N){ cout << W[i] << " "; } cout << Endl;*/ ll num = 0; REP(i,N){ if(Z[i]!=-1){ /*auto it = upper_bound(ALL(E),Z[i]);it--; ll u = distance(E.begin(),it); Ans = (Ans+((N-M-now)*u)%MOD)%MOD; Ans = (Ans+(now*(E.size()-1-u))%MOD)%MOD; cout << now MM u MM (N-M-now) MM (E.size()-1-u) << endl;*/ sum -= N-M-W[Z[i]]; sum += W[Z[i]]; }else{ num += sum; } } //num = (num*(MOD+1)/2)%MOD; num = (num*inverse(N-M,MOD))%MOD; REP(i,N-M){num = (num*(i+1))%MOD;} Ans = (Ans+num)%MOD; //cout << num << endl; //cout << Ans << endl; ll n = N-M; n = (n*(n-1)/2)%MOD; n = (n*(MOD+1)/2)%MOD; REP(i,N-M){n = (n*(i+1))%MOD;} //cout << n << endl; Ans = (Ans+n)%MOD; cout << Ans << endl; return 0; }