#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
using namespace std;
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
    while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
    return x*f;
}
const int P=998244353,N=50005;
int n,m,c[N][22],fac=1;
ll Ans;
ll fpow(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1)res=res*x%P;
        y>>=1;x=x*x%P;
    }
    return res;
}
int main(){
    n=read(),m=read();
    rep(i,1,n)rep(j,1,m){
        int x=read();
        ++c[j][x];
    }
    rep(i,1,n)fac=1ll*fac*i%P;
    rep(i,1,m){
        int sum=0,ans=1;
        per(j,n,1){
            sum+=c[i][j+1];//计算当前位置可以填的数
            ans=1ll*ans*sum%P;//乘法原理
            sum--;//减去填的数
        }
        Ans=(Ans+1-fpow(fac,P-2)*ans%P+P)%P;//该点的期望
    }
    printf("%lld\n",Ans);
    return 0;
}