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

struct fastio{fastio(){cin.tie(nullptr);ios_base::sync_with_stdio(false);std::cout<<std::fixed<<setprecision(10);}}oitsaf;
#define rep(i,n) for(int i=0;i<int(n);++i)
template<class T>std::vector<T>vec(size_t a){return std::vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a,Ts... ts){return std::vector<decltype(vec<T>(ts...))>(a,vec<T>(ts...));}
template<class T>std::istream&operator>>(std::istream&is,std::vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T>std::ostream&operator<<(std::ostream&os,std::vector<T>const&v){for(auto const& vi:v)os<<vi<<" ";return os;}

int main() {
  int n, k;
  cin >> n >> k;
  auto dist = vec<int>(n, n);
  cin >> dist;
  vector<int> idx(n - 1);
  iota(begin(idx), end(idx), 1);
  int ans = 0;
  do {
    int tmp = dist[0][idx[0]];
    rep(i, n - 2) tmp += dist[idx[i]][idx[i + 1]];
    tmp += dist[idx[n - 2]][0];
    ans += tmp==k;
  } while (next_permutation(begin(idx), end(idx)));
  cout << (ans) << endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll g[20][20];
ll a[20],n,k,res;
bool vis[20];
void dfs(int t)
{
	if(t > n)
	{
		int ans = 0;
		for(int i = 2;i <= n;i++)
		{
			ans += g[a[i-1]][a[i]];
		}
		ans += g[a[n]][1];
		if(ans == k) res++;
	}	
	else{
		for(ll i = 2;i <= n;i++)
		{
			if(!vis[i])
			{
				vis[i]=true;
				a[t]=i;
				dfs(t+1);
				vis[i]=false;
				a[t]=0;
			}
		}
	}
}
int main()
{
	scanf("%lld%lld",&n,&k);
	for(int i = 1;i <= n;i++)
	{
		for(int j = 1;j <= n;j++)
		{
			scanf("%lld",&g[i][j]);
		}
	}
	a[1]=1;
	vis[1] = true;
	dfs(2);
	printf("%lld",res);
	return 0;
}