#include<bits/stdc++.h>
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];
    }
  }
  
  int array[N-1];
  for(int i=2; i<=N; i++){
    array[i-2] = i;
  }
  int temp;
  int time;
  int count = 0;
  do {
    temp = 1;
    time = 0;
    for (int i = 0; i < N-1; i++) {
      time += T.at(temp-1).at(array[i]-1);
      temp = array[i];
    }
    time += T.at(temp-1).at(0);
    if(time == K) count++;
  }while (next_permutation(array, array + N-1));
  cout << count << endl;
}
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <map>
#include <tuple>  
#define for1(x,y) for(long long x = 1; x<ll(y); x++)
#define forn(x,y,z) for(long long x = y; x< ll(z); x++)
#define for0(x,y,z) for(long long x = y; x< ll(z); x++)
#define PII pair<int,int>
#define FF first
#define SS second
#define PB push_back
#define all(x) x.begin(), x.end()

#define forn(x,y,z) for(long long x = y; x< ll(z); x++)
#define for0(x,y,z) for(long long x = y; x< ll(z); x++)
using namespace std;

//Errichto Orz debug template

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// ends debug

// aliases
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using ld = long double;


#define vi vector<int> 
#define vl vector<ll> 
#define pb(x) push_back(x)
const double EPS = (1e-7), EPSm= (1e7);
const ll linf = (ll)1e17 + 5;
long double PI = 3.14159265359;
int dir[8][2]={{1,0},{-1,0},{0,1},{0,-1},{-1,-1},{1,1},{-1,1},{1,-1}};
	
const int MAXN = 1e5+10;
const int NINF = -1e5;
const int INF = 20000000;
const ll MOD = 1e9+7;

	
// Mathematical functions.
 
int GCD(int a, int b)
{
	if (!b)
		return a;
	return GCD(b, a % b);
}
 
int LCM(int a, int b)
{
	return (a * b) / GCD(a, b);
}
 
int modpow(int x, int n, int m = MOD)
{
	if (n == 0) return 1 % m;
	long long u = modpow(x, n / 2, m);
	u = (u * u) % m;
	if (n % 2 == 1)
		u = (u * x) % m;
	return u;	
}
 
/**
 * m should be prime
 */
int modinv(int x, int m = MOD)
{
	return modpow(x, m - 2, m);
}
 
//////////////////// START CODE HERE ///////////////////////////
int n,k;
int dis[9][9];
map<ll,int> ans;

void f(int mask,int d, int pos){
	if(mask==(1<<n)-1){
		ans[d+dis[pos][0]]++;
		return;
	}
	else {
		forn(i,0,n){
			if((mask&(1<<i))==0){
				f(mask|(1<<i),d+dis[pos][i],i);
			}
		}
	}
}

void solve()
{
	cin>>n>>k;
	forn(i,0,n){
		forn(j,0,n) cin>>dis[i][j];
	}
	f(1,0,0);
	cout<<ans[k];
	return;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int test;
	//cin >> test;
	//while(test--)
		solve();
	return 0;
}
