#include <iostream>
using namespace std;
long long int n,goal,t[9][9],ans;
bool used[9];
void dfs(int sum,int it,int step){
	if(step==n-1){
		if(sum+t[it][0]==goal){
			++ans;
		}
		return;
	}
	for(int i=1;i<n;++i){
		if(!used[i]&&t[it][i]+sum<=goal){
			used[i]=1;
			dfs(t[it][i]+sum,i,step+1);
			used[i]=0;
		}
	}
}
int main(){
	while(cin >> n >> goal){
		for(int i=0;i<n;++i){
			used[i]=0;
			for(int j=0;j<n;++j)
				cin >> t[i][j];
		}
		ans=0;
		used[0]=1;
		dfs(0,0,0);
		cout << ans << "\n";
	}
} 
#include <bits/stdc++.h>
using namespace std;

int64_t MOD = 1000000007;
double PI = 3.141592653589793;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<vector<int>> list(N, vector<int>(N));
    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
            cin >> list[i][j];
    vector<int> route(N - 1);
    for (int i = 0; i < N - 1; i++)
        route[i] = i + 1;

    int ans = 0;
    do
    {
        int tmp = 0;
        tmp += list[0][route[0]] + list[0][route[N - 2]];
        for (int i = 0; i < N - 2; i++)
            tmp += list[route[i]][route[i + 1]];
        if (tmp == K)
            ans++;
    } while (next_permutation(route.begin(), route.end()));
    cout << ans;
}