#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[10][10],num[10];
int main()
{
	ll n,k,res=0;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			cin>>a[i][j];
	for(int i=1;i<=n;i++)
		num[i]=i;	
	do
	{
		ll last,now,sum=0;
		for(int i=1;i<n;i++)
		{
			last=num[i];
			now=num[i+1];
			sum=sum+a[last][now];	
		}
		sum=sum+a[1][num[n]];
		if(sum==k)
			res++;
	}while(next_permutation(num+2,num+1+n));
	cout<<res;
	return 0;
}
#include<bits/stdc++.h>
using namespace std; 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define length size()
#define int long long
#define ll long long
#include <cstdint>
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
const int MOD = 1000000007;
const int mod = 1000000007;
const int MAX = 510000;
const double inf = 900719925474099;
template<typename T> string join(vector<T> &vec ,const string &sp){
    int si = vec.length;
    if(si==0){
        return "";
    }else{
        stringstream ss;
        rep(i,si-1){
            ss << vec[i] << sp;
        }
        ss << vec[si - 1];
        return ss.str();
    }
}
vector<vector<int>> ruiseki2d(vector<vector<int>> vec){
    rep(i,vec.size()-1){
        rep(j,vec[0].size()-1){
            vec[i+1][j+1] = vec[i][j+1]+vec[i+1][j]-vec[i][j]+vec[i+1][j+1];
        }
    }
    return vec;
}
vector<int> ruiseki(vector<int> vec){
    rep(i,vec.size()-1){
        vec[i+1] += vec[i];
    }
    return vec;
}
int t,s;
int solve(int a){
    return (a<0)?a*s:a*t;
}
signed main(void){
    int n,k;
    cin >> n >> k;
    vector<int> vec(n-1);
    vector<vector<int>> town(n,vector<int>(n));
    rep(i,n-1){
        vec[i] = i+1;
    }
    rep(i,n){
        rep(j,n){
            cin >> town[i][j];
        }
    }
    int ans = 0;
    do {
        //cout << join(vec," ") <<endl;
        int sum = 0;
        int now = 0;
        for(int i=0;i<n-1;i++){
            int next = vec[i];
            sum += town[now][next];
            now = next;
        }
        sum += town[now][0];
        if(sum == k) ans++;
    }while (std::next_permutation(vec.begin(),vec.end()));
    cout << ans << endl;
}
