// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int ll
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define ll long long
#define pi pair<int,int> 
#define pii pair<pi,int>
#define vi vector<int>
#define pb push_back 
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a >= mod)a %= mod;
}
int n,k;
int a[10][10];
int ans;
void find(vi v,int cost,int cur){
	// cout<<cur<<" ";
	if(s(v) == 0){
		// cout<<cost<<"\n";
		if(cost + a[cur][0] == k){
			ans++;
		}
		return;
	}
	rep(i,s(v)){
		vi new_v;
		rep(j,s(v)){
			if(j == i)continue;
			new_v.pb(v[j]);
		}
		find(new_v,cost+a[cur][v[i]],v[i]);
	}
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>k;
	rep(i,n){
		rep(j,n){
			cin>>a[i][j];
		}
	}
	vi v;
	repa(i,1,n)v.pb(i);
	find(v,0,0);
	cout<<ans;
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main(){
	int aa,b,t=0,sum=0;
	cin>>aa>>b;
	int d[aa+1][aa+1];
	for(int i=1;i<=aa;i++){
		for(int ii=1;ii<=aa;ii++){
			cin>>d[i][ii];
		}
	}
	
    int a[aa+2],e[aa+2],c[aa+2],z[aa+2];
	c[1]=1;c[aa+1]=1;e[1]=1;e[aa+1]=1;z[1]=1;z[1+aa]=1;
    
	for(int i=0;i<=aa-2;i++)a[i]=i+2;
    do{
        for(int i=0;i<=aa-2;i++){
        c[i+2]=a[i];
		z[i+2]=a[i];
        e[i+2]=a[i];
        }
		for(int i=1;i<=aa;i++){
        	
        	sum+=d[e[i]][e[i+1]];
			if(sum==b)t+=1;
		}
    	sum=0;
    } while (next_permutation(a,a+aa-1));
    cout<<t;
    return 0;
}