#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 25;
const int maxm = 100000+10;
const LL mo = 998244353;

int n,m;
int a[maxn][maxm];
int cnt[maxn];
LL fac;
LL A[maxn][maxn];

LL power(LL x,LL y)
{
    LL ans=1;
    while (y)
    {
        if (y&1) ans=ans*x%mo;
        x=x*x%mo;
        y>>=1;
    }
    return ans;
}

int main()
{
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=m;j++) scanf("%d",&a[i][j]);
    }
    for (int i=0;i<=n;i++)
    {
        A[i][0]=1;
        for (int j=1;j<=i;j++)
        {
            A[i][j]=A[i][j-1]*(LL)(i-j+1)%mo;
        }
    }
    fac=1;
    for (int i=1;i<=n;i++) fac=fac*i%mo;
    LL Ans=0;
    for (int j=1;j<=m;j++)
    {
        memset(cnt,0,sizeof(cnt));
        for (int i=1;i<=n;i++) cnt[a[i][j]-1]++;
        //for (int i=0;i<=n;i++) printf("%d ",cnt[i]); printf("\n");
        LL ans=1;
        int pre=0;
        for (int i=1;i<=n;i++)
        {
            pre+=cnt[i-1];
            if (pre>i-1||pre+cnt[i]>i)
            {
                ans=0;
                break;
            }
            ans=ans*A[i-pre][cnt[i]]%mo;
        }
        //printf("%lld\n",fac-ans);
        Ans=(Ans+fac-ans+mo)%mo;
    }
    Ans=Ans*power(fac,mo-2)%mo;
    cout << Ans << endl;
    return 0;
}
