#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i=0; i<(ll)n; i++)
#define ALL(obj) begin(obj), end(obj)
typedef long long ll;
int n, m, a, b, cnt;
vector<vector<int> > G(22);
vector<int> color(22, -1), ts;
vector<bool> vit(22, 0);

void dfs(int now){
	ts.push_back(now);
	vit[now]=1;
	
	for(int i : G[now]){
		if(!vit[i])
		    dfs(i);
	}
}

ll DFS(int i){
	if(i==ts.size())
	    return 1;
	    
	ll ret=0;
	rep(j, 3){
		bool f=1;
		for(int v:G[ts[i]]){
			if(color[v]==j)
			    f=0;
		} 
		
		if(!f)
		    continue;
		    
		color[ts[i]]=j;
		ret+=DFS(i+1);
		color[ts[i]]=-1;
	}
	
	return ret;
}

int main()
{
	cin>>n>>m;
	ll ans=1;
	rep(i, m){
		cin>>a>>b;
		a--;
		b--;
		
		G[a].push_back(b);
		G[b].push_back(a);
	}
	
	rep(i, n){
		if(vit[i])
		    continue;
		    
		dfs(i);
		fill(ALL(color), -1);
		ans*=DFS(0);
		ts.clear();
	}
	
	cout<<ans<<endl;
	return 0;
}

#include <iostream>
#include <math.h>
#include <vector>

using namespace std;

const int MOD = 998244353;
typedef pair <int,int> ii;

long long fac(long long a){
	if(a==0)return 1;
	return (a*fac(a-1))%MOD;
}

int n, k;

int en[50][50];

vector < vector <int> > mc, mr;

int vi[50][2];

bool cc(int i, int j){
	for(int it=0;it<n;it++)if(en[it][i]+en[it][j]>k)return false;
	return true;
}

bool cr(int i, int j){
	for(int it=0;it<n;it++)if(en[i][it]+en[j][it]>k)return false;
	return true;
}

long long cal(int ac, vector < vector <int> > &ad, int ve){
	vi[ac][ve] = 1;
	long long res = 1;
	for(int i=0;i<ad[ac].size();i++)if(!vi[ad[ac][i]][ve]){
		res += cal(ad[ac][i], ad, ve);
	}
	return res;
}
int main(){
	
	cin.tie(0); ios_base::sync_with_stdio(0);
	cin>>n>>k;
	for(int i =0;i<n;i++)for(int j=0;j<n;j++){
		cin>>en[i][j];
	}
	mr.resize(n);
	mc.resize(n);
	long long res = 1;
	for(int i=0;i<n;i++)for(int j = i+1;j<n;j++){
		if(cc(i,j)){
			mc[i].push_back(j);
			mc[j].push_back(i);
		}
		
		if(cr(i,j)){
			mr[i].push_back(j);
			mr[j].push_back(i);
		}
	}
	
	for(int i=0;i<n;i++){
		if(!vi[i][0]){
			res = (res * fac(cal(i, mr, 0)))%MOD;
		}
		if(!vi[i][1]){
			res = (res * fac(cal(i, mc, 1)))%MOD;
		}
	}
	
	cout<<res<<endl;
		
	return 0;
}