#include<bits/stdc++.h>
#define mod 998244353
using namespace std;
struct DSU{
    int n;
    int parent[55];
    int size[55];
    void init(int _n){
        n = _n;
        for(int i=1;i<=n;i++){
            parent[i]=i;
            size[i]=1;
        }
    }
    int findSet(int i){
        if(parent[i]==i)return i;
        return parent[i]=findSet(parent[i]); 
    }
    void unionSet(int u, int v){
        u = findSet(u), v = findSet(v);
        if(u!=v){
            if(size[u]<size[v]){
                parent[u]=v;
                size[v]+=size[u];
            }else{
                parent[v]=u;
                size[u]+=size[v];
            }
        }
    }
    vector<int>sz(){
        vector<int>res;
        for(int i=1;i<=n;i++){
            if(parent[i]==i)res.push_back(size[i]);
        }
        return res;
    }
};
long long fact(int n){
    if(n==1)return 1;
    else return (n%mod*fact(n-1)%mod)%mod;
}
int main(){
    int n,K;cin>>n>>K;
    int a[n+5][n+5];
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            cin>>a[i][j];

    DSU dsu;
    dsu.init(n);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            bool valid = true;
            for(int k=1;k<=n;k++){
                if(a[k][i] + a[k][j] > K){
                    valid=false;
                    break;
                }  
            }if(valid)dsu.unionSet(i,j);
        }
    }
    long long ans = 1;
    for(int x : dsu.sz()){
        // cout<<x<<endl;
        ans = (1LL * fact(x) * ans )%mod;
    }

    dsu.init(n);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            bool valid = true;
            for(int k=1;k<=n;k++){
                if(a[i][k] + a[j][k] > K){
                    valid=false;
                }
                
            }if(valid){
                    dsu.unionSet(i,j);
                }
        }
    }
    for(int x : dsu.sz()){
       ans = (ans * 1LL * fact(x))%mod;
    }
    cout<<ans<<endl;
}
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<cstdio>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return tmp;
}

int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint();
	int kotae = 2e9;

	rep(i, N) {
		int a = getint();
		int p = getint();
		int x = getint();
		if (a < x && p < kotae) kotae = p;
	}

	if (kotae > 1e9) printf("-1");
	else printf("%d", kotae);

	Would you please return 0;
}