#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)     for(long long int i=a; i<n; i++)
#define loop(i,a,n)     for(long long int i=a; i>=n; i--) 

int main()
{
	ios_base :: sync_with_stdio(false),cin.tie(NULL);
	
	long long int a, b, ans=0;
	cin>>a>>b;
	string s="";
	forr(i, 0, a)
		s+=(i+'0');
	long long int c[a][a];
	forr(i, 0, a)
	{
		forr(j, 0, a)
			cin>>c[i][j];
	}
	do{
		if(s[0]=='0')
		{
			int l=0, kk=0;
			forr(i, 0, s.size())
			{
				kk+=c[l][s[i]-'0'];
				l=s[i]-'0';
			}
			kk+=c[l][0];
			//cout<<kk<<'\n';
			if(kk==b)
				ans++;
		}
		else
			break;
	
	}while(next_permutation(s.begin(), s.end()));
	cout<<ans;
	
	return 0;
}
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;


int main(){
	int n,k;
	cin >> n >> k;
	vector<vector<int>> T(n, vector<int>(n));
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			cin >> T[i][j];
		}
	}

	vector<int> index;
	for(int i=0; i<n; i++)index.push_back(i);

	int ans = 0;
	do{
		int time = 0;
		for(int i=0; i<n; i++) time += T[index[i]][index[(i+1)%n]];
		if(time == k) ans++;
	}while(next_permutation(index.begin()+1, index.end()));

	cout << ans << endl;
}
