#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
int main(){
  int n,k,ans=0;
  cin>>n>>k;
  int grid[n][n];
  rep(i,n)rep(j,n) cin>>grid[i][j];
  vector<int> v;
  rep(i,n) v.push_back(i+1);
  do {
      ll loop = 0;
      rep(i,n-1){
        loop += grid[v[i]-1][v[i+1]-1];
      }
      loop += grid[v[n-1]-1][v[0]-1];
      if(loop == k) ans++;
    } while(next_permutation(v.begin(), v.end()));
  ans /= n;
  cout << ans << endl;
}
#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = int64_t; using ull = uint64_t; using pll = pair<ll,ll>; const ll INF = 4e18;
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);}
void print() { print0("\n"); }
template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);}
// clang-format on

vector<vector<ll>> route(9, vector<ll>(9, -1));
ll N;
ll cnt = 0;
ll K;
vector<bool> done(9, false);
void recursive(ll c, ll ttl) {
    //print(c, ttl, K);
    done[c] = true;
    bool all = true;
    for (ll j = 0; j < N; j++) {
        if (!done[j]) {
            all = false;
        }
    }
    if (all) {
        // print(ttl, c);
        if (ttl + route[c][0] == K) {
            cnt++;
        }
        done[c] = false;
        return;
    }
    for (ll j = 0; j < N; j++) {
        if (!done[j]) {
            //    print(c, j);
            recursive(j, ttl + route[c][j]);
        }
    }
    done[c] = false;
}

int main() {
    cin >> N >> K;

    for (ll i = 0; i < N; i++) {
        for (ll j = 0; j < N; j++) {
            ll t;
            cin >> t;
            route[i][j] = t;
        }
    }
    recursive(0, 0);
    print(cnt);
}
