#include <bits/stdc++.h>

#define rep( i, a, b ) for( i = a; i < b; i ++ )

using namespace std;
template< class T >
using vv = vector< vector< T > >;

int solve( vv< int > *dvv, vector< int > rv, int ind, int a, int d ) {
    int p = rv.at( ind );
    rv.erase( rv.begin() + ind );
    if( rv.empty() ) {
        int b = d + dvv->at( p ).at( 0 );
        return a == b ? 1 : 0;
    }
    int cn = 0, i;
    rep( i, 0, rv.size() ) {
        cn += solve( dvv, rv, i, a, d + dvv->at( p ).at( rv.at( i ) ) );
    }
    return cn;
}

int main() {
    vv< int > dvv;
    vector< int > rv;
    int c, a, i, j, d;
    cin >> c >> a;
    rep( i, 0, c ) {
        vector< int > dv;
        rep( j, 0, c ) {
            cin >> d;
            dv.push_back( d );
        }
        dvv.push_back( dv );
    }
    rep( i, 0, c ) {
        rv.push_back( i );
    }
    cout << solve( &dvv, rv, 0, a, 0 ) << endl;
    return 0;
}
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <limits>
#include <numeric>
#include <vector>

using namespace std;

// static constexpr long long INF = numeric_limits<long long>::max() / 2;

// vector<long long> travel(int S, int v, int N, int K, int counter, vector<long long>& T, vector<long long>& dp) {
//   if (dp[S][v] >= 0) {
//     vector<long long> ans = { dp[S][v] };
//   }

//   // if (S == ((1 << N) - 1) && dp[S][v] == K) {
//   //   counter++;
//   // }

//   if (S == (1 << N) - 1 && v == 0) {
//     return dp[S][v] = 0;
//   }

//   long long res = INF;
//   for (int u = 0; u < N; u++) {
//     if (!(S >> u & 1)) {
//       long long total = travel(S | (1 << u), u, N, K, counter, T, dp) + T[v][u];
//       if (total == K) {
//         counter++;
//       }
//       res = counter;
//     }
//   }
//   return dp[S][v] = res;
// }

int main() {
  int N, K;
  cin >> N >> K;
  vector<vector<long long>> T(N, vector<long long>(N));

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      long long t;
      cin >> t;
      T[i][j] = t;
    }
  }

  vector<long long> cities(N+1);
  iota(cities.begin(), cities.end(), 0);
  cities[N] = 0;

  long long counter = 0;
  do {
    long long total = 0;
    for (int i = 0; i <= N; i++) {
      if (i == N) {
        total += T[cities[i]][0];
      } else {
        total += T[cities[i]][cities[i+1]];
      }
    }
    if (total == K) {
      counter++;
    }
  } while(next_permutation(cities.begin()+1, cities.end()));

  cout << counter << endl;

  
  // // vector<long long> dp(1 << N, vector<long long>(N, -1));
  // vector<long long> dp(1 << N, -1);

  // for (int i = 0; i < (1 << N); i++) {
  //   long long cost = 0;
  //   for (int j = 0; j < N; j++) {
  //     if (i >> j & 0x1) {
        
  //     }
  //   }
  // }
  
  
  return 0;
}
