#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define black_tree tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define pair_black_tree tree<pair<ll,ll>,null_type,less_equal<pair<ll,ll>>,rb_tree_tag,tree_order_statistics_node_update>
#define gp __gnu_pbds
#define INF 1000000000
#define MOD 1000000007
#define MAX 1000001
#define endl '\n'
#define ll long long
#define ld long double
#define lli long long int
#define ull unsigned long long
#define ulli unsigned long long int
#define pb push_back
#define pf push_front
#define ook order_of_key
#define fbo find_by_order
#define ffo find_first_of
#define np next_permutation
#define mp make_pair
#define eb emplace_back
#define mae max_element
#define mie min_element
#define bs binary_search
#define lb lower_bound 
#define ub upper_bound
#define ff first
#define ss second
using namespace std;
using namespace gp;
vector<ll>v;
ll n,k,ans,cnt,g[9][9];
string add(string a,string b){
	if(a.size()>b.size()) swap(a,b);
	string s="";
	ll l1=a.size(),l2=b.size(),diff=l2-l1,carry=0;
	for(int i=l1-1;i>=0;i--){
		ll num=(a[i]-'0'+b[i+diff]-'0')+carry;
		s.pb(num%10+'0');
		carry=num/10;
	}
	for(int i=l2-l1-1;i>=0;i--){
		ll num=b[i]-'0'+carry;
		s.pb(num%10+'0');
		carry=num/10;
	}
	if(carry) s.pb(carry+'0');
	reverse(s.begin(),s.end());
	return s;
}
string multiply(string a,string b){
	if(a.empty() || b.empty()) return "0";
	ll l1=a.size(),l2=b.size(),fi=0,fj=0,carry,num1,num2;
	vector<ll>result(l1+l2,0LL);
	for(int i=l1-1;i>=0;i--){
		carry=0,num1=a[i]-'0',fj=0;
		for(int j=l2-1;j>=0;j--){
			num2=b[j]-'0';
			ll sum=num1*num2+result[fi+fj]+carry;
			carry=sum/10;
			result[fi+fj]=sum%10;
			fj++;
		}
		if(carry) result[fi+fj]+=carry;
		fi++;
	}
	ll i=result.size()-1;
	while(i>=0 && !result[i]) i--;
	if(i==-1) return "0";
	string s="";
	while(i>=0) s+=to_string(result[i--]);
	return s;
}
int main(){
	//freopen("file.in","r",stdin);
	//freopen("file.out","w",stdout);
	ios_base::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>>g[i][j];
		}
	}
	for(int i=2;i<=n;i++) v.pb(i);
	do{
		ans=0;
		ans+=g[1][v[0]];
		for(int i=1;i<v.size();i++) ans+=g[v[i-1]][v[i]];
		ans+=g[v[v.size()-1]][1];
		if(ans==k) cnt++;
	}
	while(np(v.begin(),v.end()));
	cout<<cnt;
}
#include<bits/stdc++.h>
using namespace std;
#define speed ios_base::sync_with_stdio;cin.tie(nullptr);cin.tie(nullptr);
typedef long long int ll;
#define t int t;cin>>t;while(t--)
#define For(n) for(int i=0;i<n;i++)
#define ne(a) int a;cin>>a;
bool great(pair<int,int>a,pair<int,int>b)
{
	return (a.first<b.first);
}
template<class c>
c gcd (c a,c b)
{
	if(b==0)
		return a;
	gcd(b,a%b);
}
int main()
{
	speed
	ne(n) ne(k)
	int arr[n][n];
	for(int i=0;i<n;i++)
	{
		for(int j =0;j<n;j++)
		{
			cin>>arr[i][j];	
		}
	}
	int count =0;int result = 0;
	int tarr[n];
	for(int i =0;i<n;i++)
	{
		tarr[i] = i;
	}
		
	do { 
		int count =0;
       	for(int i=0;i<n;i++)
       	{
       		count+=arr[tarr[i]][tarr[(i+1)%n]];
       	}
       	if(count==k)
       		result++;
  	} while (next_permutation(tarr+1, tarr + n)); 
	cout<<result<<endl;
}