#include <bits/stdc++.h>
using namespace std; 
#define ll long long
#define pb push_back
#define inf 1000000000
int n,k;
vector<vector<int> > edges(100);
int main(){
	cin >> n >> k;	
	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++){
			edges[i].pb(0);
		}
	}
	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++){
			cin >> edges[i][j];
			edges[j][i]=edges[i][j];

		}		
	}

	int a[n+1];
	for(int i=1;i<n+1; i++) a[i] = i;
	int cnt=0;
	do{
			ll sum=0;

		for(int i=2; i<n+1; i++){
			sum+=edges[a[i-1]][a[i]];
		}
		sum+=edges[a[n]][a[1]];
		if(sum == k) cnt++;
	}while(next_permutation(a+2, a+n+1));
	cout << cnt;
	
	return 0; 
}
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
ll MODP = 998244353;

ll lmax(ll x,ll y){
  if(x < y) return y;
  else return x;
}

ll lmin(ll x, ll y){
  if(x > y)return y;
  else return x;
}

ll gcd(ll x,ll y){
  while(y > 0){
    if(x < y) swap(x,y);
    return gcd(y,x%y);
  }
  return x;
}

int main(){
  ll n,k;
  cin >> n >> k;
  vector<vector<ll>> dist(n,vector<ll>(n));
  rep(i,n)rep(j,n){
    ll a;
    cin >> a;
    dist[i][j] = a;
  }
  vector<ll> array(n);
  vector<vector<ll>> how;
  rep(i,n)array[i] = i+1;
  do{
    vector<ll> res(n);
    for(int i=0; i<n; i++){
      res[i] = array[i];
    }
    how.push_back(res);
  }while(next_permutation(array.begin(),array.end()));
  ll ans = 0;
  for(auto x : how){
    if(x[0] !=  1)continue;
    ll sum = 0;
    ll d = x.size();
    for(int i = 0;i < d - 1;i++){
      sum += dist[x[i]-1][x[i+1]-1];
    }
    sum += dist[x[d-1]-1][0];
    if(sum == k)ans++;
  }
  cout << ans <<endl;

  return 0;
}
