#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main(){
  int n,k;
  cin >> n >> k;
  vvi t(n, vi(n));
  REP(i,n)REP(j,n)cin >> t[i][j];

  vi a(n-1);
  iota(ALL(a),1);
  int ans=0;
  do {
    int d=0;
    d += t[0][a[0]];
    REP(i,n-2)d+=t[a[i]][a[i+1]];
    d += t[a[n-2]][0];
    if(d==k)ans++;
  } while( next_permutation(a.begin(), a.end()) );
  cout << ans << endl;
}


//author-micheal corleone
//the godfather
#include <bits/stdc++.h>
#include <set> 
#include<algorithm>
#include <set> 
#include<algorithm>
#define ll long long int
#define in(n) scanf("%lld",&n)
#define in2(a,b) scanf("%lld %lld",&a,&b)
#define out(n) printf("%lld\n",n)
#define inf 999999999999999999
#define endl "\n"
#define precise(x) fixed << setprecision(x) 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
const int mod =1000000007;
#define f(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
 
using namespace std;

bool sortcol( const vector<int>& v1, 
               const vector<int>& v2 ) { 
 return v1[1] < v2[1]; 
}
 ll mod_pow(int a,int b,int M = mod)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}
 //ll power(ll x, ll y) 
//{ 
  //  ll temp; 
    //if( y == 0) 
     //   return 1; 
    //temp = power(x, y/2); 
    //temp=temp%MOD;
    //if (y%2 == 0) 
     //   return (temp%MOD)*(temp%MOD); 
    //else
      //  return (x%MOD)*(temp%MOD)*(temp%MOD); 
//} 
 
 
ll ncr(ll n,ll r){if(n==1 || r==0)return 1;if(r>n/2)r=n-r;
	ll ans=1;for(ll i=1;i<=r;i++){ans=((ans * n )/i);n--;}return ans;
}
ll ncrsum(ll n,ll r, ll mod){
    if(n==1 || r==0)return 1;
  //  ll ans=1,sum=1;for(ll i=1;i<=r;i++){ans=((((ans * n)%MOD )*modinv(i,MOD))%mod);n--;sum+=ans;sum%=mod;}return sum;
}
 //diamond[2000005],ans[1000006];
 const int maxn=3e5+100;
 ll maximum=4000000;
 
 vector<ll> primes;
 
void SieveOfEratosthenes() 
{ 
   
    vector<ll> prime(maximum+1,1); 
   // memset(prime, 1, sizeof(prime)); 
  
    for (ll p=2; p*p<=maximum; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == 1) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (ll i=p*p; i<=maximum; i += p) 
                prime[i] = 0; 
        } 
    } 
  
    
    for (ll p=2; p<=maximum; p++) 
    {
    	if (prime[p])
		{
			primes.pb(p); 
		 }     
	}
       
} 
 ll  a[20];
 ll n,k;
ll timing[50][50];
ll answer=0;
ll final_answer=0;
void findPermutations(ll a[], ll n) 
{ 
    sort(a,a+n); 
    do { 
        answer=0;
        answer=answer+timing[1][a[0]];
        for(ll i=0;i<n-1;i++)
		{
			answer=answer+timing[a[i]][a[i+1]];
		 } 
		 answer=answer+timing[a[n-1]][1];
		 if(answer==k) final_answer++;
		 
		 //cout<<answer<<endl;
    } while (next_permutation(a, a + n)); 
} 
  
 
 
int main()
{
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
     ll ta;
    //cin>>ta;
    //SieveOfEratosthenes();
    ta=1;	
     for(ll testcase=0;testcase<ta;testcase++)
    {
        ll i1,i2,j,j1,a1,i31,i3,j2,i5,i4,i6,i7,i,m,t;
        ll x,y,z,l;
        ll total=0,cnt=0;
        ll flag=0,flag1=0;
        y=0;
        ll res,res1,ans,res2,sum,curr;
        ans=0,cnt=0;
        res1=0,res=0,sum=0;
        ll required,days,h,w;
        ll s1=0;
         ll k1,k2,k3,k4,p;
        k1=0,k2=0,k3=0,k4=0;
        //for(it=mp.begin();it!=mp.end(),it++)
        //{
        //	for(int i=0;i<it->second.size();i++) cout<<it->second[i]<<" ";
		//}
	    string s;
	    cin>>n>>k;
	    
	    
	    for(i=1;i<=n;i++)
	    {
	    	for(j=1;j<=n;j++)
	    	{
	    		cin>>timing[i][j];
			}
		}
	    
	    for(i=2;i<=n;i++)
	    {
	    	a[s1]=i;
	    	s1++;
		}
		findPermutations(a,n-1);
		cout<<final_answer<<endl;
	}
	   
	
    
}
	