typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;

int main() {
    ll n,k;
    std::cin >> n>>k;
    vector<vector<ll>> t(n,vector<ll>(n));
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            std::cin >> t[i][j];
        }
    }
    
    ll ans = 0;
    vector<bool> used(n,false);
    function<void(ll,ll,ll,ll)> rec = [&] (ll fir, ll sum, ll now, ll cnt) {
        if(cnt==n){
            if(sum+t[now][fir]==k) ans++;
            // std::cout << sum+t[now][fir] << std::endl;
            return;
        }
        
        for (int i = 0; i < n; i++) {
            if(used[i])continue;
            used[i] = true;
            rec(fir, sum + t[now][i], i, cnt+1);
            used[i] = false;
        }
    };
    for (int i = 0; i < n; i++) {
        used[i] = true;
        rec(i, 0,i,1);
        used[i] = false;
    }
    
    std::cout << ans/n << std::endl;
    
}

#include<bits/stdc++.h>
#define R register
#define ll long long
using namespace std;
const int MAXN =25;
vector <int> edge[MAXN];
int tot,dfn[MAXN],col[MAXN],pos[MAXN];
int n,m;
ll ans;
bool vis[MAXN];
void make_list(int k)
{
	if(vis[k]) return ;
	vis[k]=1;
	dfn[++tot]=k;
	pos[k]=tot;
	for(R int i=0;i<edge[k].size();++i)
		make_list(edge[k][i]);
}
void dfs(int now,ll sum)
{
	if(now>tot)
	{
		ans+=sum;
		return ;
	}
	int f[4];
	memset(f,0,sizeof f);
	bool flag=0;
	for(R int i=0;i<edge[dfn[now]].size();++i)
	{
		int to=edge[dfn[now]][i];
		if(pos[to]<now) f[col[to]]=1;
		else flag=1;
	}
	int k=0;
	for(R int i=1;i<=3;++i) 
		k+=(f[i]==0);
	if(!flag) dfs(now+1,sum*k);
	else
	{
		for(R int i=1;i<=3;++i)
		{
			if(f[i]) continue;
			col[dfn[now]]=i;
			dfs(now+1,sum);
//			col[now]=0;
		}
	}
}
int main()
{
	scanf("%d %d",&n,&m);
	for(R int i=1;i<=m;++i)
	{
		int u,v;
		scanf("%d %d",&u,&v);
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
	ll res=1;
	for(R int i=1;i<=n;++i)
	{
		if(vis[i]) continue;
		tot=0;
		ans=0;
		make_list(i);
		dfs(1,1);
		res*=ans;
	}
	printf("%lld",res);
	return 0;
}