#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<vector>
#define ll long long
using namespace std;

int n;
ll k,ans=0;
int t[9][9];
int num[]={2,3,4,5,6,7,8};

void solve(){
	do{
		ll sum=0;
		sum+=(t[1][num[0]]+t[num[n-2]][1]);
		for(int i=0;i<n-2;i++)	sum+=t[num[i]][num[i+1]];
		if(sum==k)	ans++;
	}while(next_permutation(num,num+n-1));
}
int	main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++){
			cin>>t[i][j];
		}
	solve();
	cout<<ans;
}

/* Simplicity and Goodness */

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) { cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=a; i<(int)b; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int maxN = 1e6+2;

int t[10][10];
int n, k;

bool check(vi order)
{
   int prv = 1;
   ll cost = 0;

   rep(i, 0, n - 1) {
      int to = order[i];
      cost += t[prv][to];
      prv = to;
   }

   cost += t[prv][1];

   return cost == k;
}

int main()
{
   scn(n); scn(k);

   rep(i, 1, n + 1) {
      rep(j, 1, n + 1) {
         scn(t[i][j]);
      }
   }

   vi permute;

   rep(i, 2, n + 1)
   permute.pb(i);

   int cnt = 0;

   do {
      cnt += check(permute);
   } while(next_permutation(permute.begin(), permute.end()));

   prin(cnt);

   return 0;
}