// Problem: E. Assimilation IV
// Contest: Codeforces - Educational Codeforces Round 109 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1525/problem/E
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>

namespace FastIO {
	char buf[1 << 21], buf2[1 << 21], a[20], *p1 = buf, *p2 = buf, hh = '\n';
	int p, p3 = -1;
void read() {}
void print() {}
inline int getc() {
    return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++;
}
inline void flush() {
    fwrite(buf2, 1, p3 + 1, stdout), p3 = -1;
}
template <typename T, typename... T2>
inline void read(T &x, T2 &... oth) {
    int f = 0;
    x = 0;
    char ch = getc();
    while (!isdigit(ch))
    {
        if (ch == '-')
            f = 1;
        ch = getc();
    }
    while (isdigit(ch))
    {
        x = x * 10 + ch - 48;
        ch = getc();
    }
    x = f ? -x : x;
    read(oth...);
}
template <typename T, typename... T2>
inline void print(T x, T2... oth) {
    if (p3 > 1 << 20)
        flush();
    if (x < 0)
        buf2[++p3] = 45, x = -x;
    do {
        a[++p] = x % 10 + 48;
    } while (x /= 10);
    do {
        buf2[++p3] = a[p];
    } while (--p);
    buf2[++p3] = hh;
    print(oth...);
}
} // namespace FastIO
#define read FastIO::read
#define print FastIO::print
using namespace std;

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

#define int long long 
#define sz(X) ((int)(X).size())
#define fi first
#define se second
#define pb push_back
#define rep(i, a, n) for (int i = a; i <= n; i ++ ) 
#define per(i, n, a) for (int i = n; i >= a; i -- )
#define mst memset
#define endl '\n'
#define si(x) scanf("%d", &x)
#define sll(x) scanf("%lld", &x)
#define pi(x) printf("%d\n", x)
#define pll(x) printf("%lld\n", x)
#define sc scanf
#define pr printf

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef unsigned long long ull;

const int SIZE = 2e5 + 10, INF = 0x3f3f3f3f;
const int mod = 998244353;

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
const int N = 5e4 + 10;

int n, m;
LL inv[N], num[N][25];

inline LL qpow(int a, int b, int c) {
	LL ans = 1;
	while (b) {
		if (b & 1) ans = ans * a % mod;
		a = 1ll * a * a % mod;
		b >>= 1;
	}
	return ans;
}

void solve() {
	cin >> n >> m;
	rep(i, 1, n) {
		inv[i] = qpow(i, mod - 2, mod);
	}
	rep(i, 1, n) {
		rep(j, 1, m) {
			int d;
			cin >> d;
			num[j][d] ++;
		}
	}
	LL ans = 0;
	int p = 1;
	rep(j, 1, m) {
		p = 1;
		int legal = 0;
		rep(i, 1, n) {
			legal += num[j][n - i + 2];
			if (legal <= 0) {
				p = 0;
				break;
			}
			p = p * (legal - i + 1) % mod * inv[n - i + 1] %  mod;
			if (p <= 0) {
				p = 0;
				break;
			}
		}
		ans = ((ans + 1 - p) % mod + mod) % mod;
	}
	cout << ans << '\n';
}

signed main(void) {
	int t;
	//cin >> t;
	t = 1;
	while (t -- ) {
		solve();
	}
    FastIO::flush();
    return 0;
}