#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

li len(vector<vector<li>>& vec,vector<int>& kero){
  int n=kero.size(),a=0;
  
  li ret=0;
  rep(i,n){
    ret+=vec[a][kero[i]];
    a=kero[i];
  }
  ret+=vec[a][0];
  if(df)print(ret);
  return ret;
}

int main(){
  int n;
  li k; cin >>n >>k;
  vector<vector<li>> vec(n,vector<li>(n));
  rep(i,n) rep(j,n) cin >>vec[i][j];
  vector<int> kero(n-1);
  rep(i,n-1) kero[i]=i+1;
  int cnt=0;
  do{
    if(k==len(vec,kero)) cnt++;
  }while(next_permutation(kero.begin(),kero.end()));
  print(cnt);
}

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

#define int long long
#define pb push_back
#define all(v) begin(v), end(v)
#define mod (int)(1e9 + 7)
#define inf (int)(4e18)
#define N (int)(2e5 + 10)
#define ff first
#define ss second

/* Clear global containers without fail */
list<pair<int, int>> adjList[10];
int vis[10] = {};
int n, k;

int backtrack(int nd, int time) {
      if (time > k) return 0;
      vis[nd] = true;
      int ans = 0;

      for (auto it : adjList[nd]) {
            if (it.ff == 1 and time + it.ss == k) ans++;
            else if (!vis[it.ff]) ans += backtrack(it.ff, time + it.ss);
      }

      vis[nd] = false;
      return ans;
}

void testCase() {
      cin >> n >> k;
      for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                  int a; cin >> a;
                  adjList[i].pb({j, a});
            }
      }

      cout << backtrack(1, 0) << endl;
}

/* Work hard .. Calm and proceed */
int32_t main() {
      ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
      int t_c = 1;
      // cin >> t_c;
      while (t_c--)
            testCase();
}