#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int t;cin>>t;while(t--)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define ll long long
#define ld long double
#define int ll
#define pb push_back
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define ff first
#define ss second
#define INF 1000000000
#define HINF 1000000000000000
#define mem(a,b) memset(a,b,sizeof(a))
#define arrin(x,n) int x[n]; for(int o=0;o<n;o++) cin>>x[o]
#define arrout(x,n) for(int o=0;o<n;o++) cout<<x[o]<<" "; cout<<endl
#define vecin(x,n); vi x;int hool; for(int o=0;o<n;o++) {cin>>hool; x.pb(hool);}
#define vecout(x,n) for(int o=0;o<n;o++) cout<<x[o]<<" "; cout<<endl
#define all(x) x.begin(),x.end()
#define deb(x) cout<<#x<<'='<<x<<endl
#define deb2(x,y) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<endl
#define deb3(x,y,z) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<" "<<#z<<'='<<z<<endl
#define debarr(arr,n) for(int o=0;o<n;o++) deb2(o,arr[o])
#define debarrall(arr) debarr(arr,arr.size())
#define IO freopen("input.txt", "r", stdin); freopen("output.txt", "w+", stdout)
const double pi = 3.14159265358979323846;

int powersimple(int a, int b){//a^b
    int res=1;
    while(b>0){
        if(b&1)
		{res=(res*a);
		b--;}
        a=(a*a);
        b>>=1;
    }
    return res;
}

int lcm(int a,int b){
    return a*b/__gcd(a,b);
}

int ncr(int n,int k)
{
	int ans=1;
	if(k>n-k)
	k=n-k;
	for(int i=1;i<=k;i++)
	ans*=(n-i+1),ans/=i;
	return ans;
}


int power(int x,int y,int p) 
{ 
    int res = 1;  
    x = x % p;   
    while (y > 0) { 
        if (y & 1) 
            res = (res * x) % p;  
        y = y >> 1; 
        x = (x * x) % p; 
    } 
    return res; 
} 

int modInverse(int n, int p) 
{ 
    return power(n, p - 2, p); 
} 

int ncrModPFermat(int n,int r, int p) 
{ 

    if (r == 0) 
		return 1; 
    
    int fac[n + 1]; 
    fac[0] = 1; 
    for (int i = 1; i <= n; i++) 
        fac[i] = (fac[i - 1] * i) % p; 
  
    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; 
} 

int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}

///////////////END OF TEMPLATE//////////////////


void solve()
{

	int i=0,j=0,k=0,m,n,p,sum=0,cnt=0;
	cin>>n>>k;
	int arr[n][n];
	for(i=0;i<n;i++)
	for(j=0;j<n;j++)
	cin>>arr[i][j];
	
	vi po;
	for(i=1;i<n;i++)
	{
	    po.pb(i);
	}
	do{
	    sum=0;
	    sum+=arr[0][po.front()]+arr[po.back()][0];
	    for(i=0;i+1<po.size();i++)
	    {
	        sum+=arr[po[i]][po[i+1]];
	    }
	    cnt+=(sum==k);
	}
	while(next_permutation(all(po)));
	
	cout<<cnt<<endl;
	
}
int32_t main() {
    fast
    //IO;
	//cout<<fixed<<setprecision(15);
    //test
    {
        
        solve();
		
		      
    }
    return 0;
}
  











#include<iostream>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<unordered_set>
#include<set>
#include<unordered_map>
#include<map>
#include<algorithm>
#include<climits>
#include<iomanip>
#include<cstdio>
using namespace std;

#define ll long long int
#define ull unsigned long long int






/********************************/






void dfs(int index, vector<vector<int>>& distance, int n, int k, bool visited[], ll& ans, ll currentSum) {
	visited[index] = true;

	bool isEmpty = true;
	for (int i = 0; i < n; i++) {
		if (!visited[i]) {
			isEmpty = false;
			dfs(i, distance, n, k, visited, ans, currentSum + distance[index][i]);
		}
	}

	if (isEmpty) {
		currentSum += distance[index][0];
		if (currentSum == k) ans++;
	}

	visited[index] = false;
}

void solve(vector<vector<int>>& distance, int n, int k) {
	ll ans = 0;
	bool visited[n];
	for (int i = 0; i < n; i++) {
		visited[i] = false;
	}

	dfs(0, distance, n, k, visited, ans, 0LL);
	cout << ans << endl;
}



int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll t = 1;
	// cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;

		vector<vector<int>> distance;
		for (int i = 0; i < n; i++) {
			vector<int> row;
			for (int j = 0; j < n; j++) {
				int a;
				cin >> a;
				row.push_back(a);
			}
			distance.push_back(row);
		}

		solve(distance, n, k);
	}
}

