#include <iostream>
#include <algorithm>
using namespace std;

int n, k, p[59][59], tp[59][59], ds[59], sz[59];

int uf(int n)
{
	if (ds[n] == n) return n;
	return ds[n] = uf(ds[n]);
}

bool chk(int a, int b)
{
	for (int i = 1; i <= n; i++)
		if (p[i][a] + p[i][b] > k)
			return false;
	return true;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++) {
			cin >> p[i][j];
			tp[i][j] = p[i][j];
		}
	long long ans = 1, md = 998244353;
	for (int ti = 0; ti < 2; ti++) {
		for (int i = 1; i <= n; i++) {
			ds[i] = i; sz[i] = 1;
		}
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j < i; j++) {
				if (chk(i, j)) {
					int ua = uf(i), ub = uf(j);
					if (ua != ub) {
						ds[ub] = ua;
						sz[ua] += sz[ub];
					}
				}
			}
		}
		for (int i = 1; i <= n; i++)
			if (uf(i) == i)
				for (int j = 1; j <= sz[i]; j++)
					ans = (ans * j) % md;
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
				p[i][j] = tp[j][i];
	}
	cout << ans << '\n';
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define int long long

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); 

    map <int, set <int>> g ; 

    int n, m ; 
    cin >> n >> m ; 
    for (int i=0;i<m;++i) {
        int a, b ; cin >> a >> b ; 
        g[a].insert(b) ; 
    }
    set <int> res ; 
    res.insert(n) ; 
    n += n ; 
    for (auto r: g) {
        vector <int> add ; 
        int y = r.first ; 
        for (auto it: g[y]) {
            for (auto d:{1, -1}) {
                if (res.count(it+d)) add.push_back(it) ; 
            }
        }
        for (auto it: g[y]) res.erase(it) ; 
        for (auto it: add) res.insert(it) ; 
    }
    cout << res.size() << endl ; 
    return 0;
}

