#include<iostream>
#include<vector>
#include<algorithm>

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 x1,x2;
  vector<int> p;
  for(int i=1;i<n;++i) p.push_back(i);
  int sum;
  int num=0;
  do {
    sum = 0;
    x1 = 0;
      for(auto x2 : p){
        //cout<<x2+1<<" ";
        sum += t[x1][x2];
        x1 = x2;
      }
    sum += t[x1][0];
    //cout<<"sum= "<<sum<<" "<<x1<<endl;
    if(sum==k) num++;
  } while( next_permutation(p.begin(), p.end()) );
  
  cout<<num<<endl;
  
}



#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using ll = long long;
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define ALL(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; i++)

#define INF (int)1e9
#define LLINF (long long)1e12
#define MOD (int)1e9 + 7
#define PI 3.141592653589
#define PB push_back
#define F first
#define S second
#define co cout <<
#define en << endl;
#define __MAGIC__              \
  ios::sync_with_stdio(false); \
  cin.tie(nullptr);

#define YESNO(T)           \
  if (T)                   \
  {                        \
    cout << "YES" << endl; \
  }                        \
  else                     \
  {                        \
    cout << "NO" << endl;  \
  }
#define yesno(T)           \
  if (T)                   \
  {                        \
    cout << "yes" << endl; \
  }                        \
  else                     \
  {                        \
    cout << "no" << endl;  \
  }
#define YesNo(T)           \
  if (T)                   \
  {                        \
    cout << "Yes" << endl; \
  }                        \
  else                     \
  {                        \
    cout << "No" << endl;  \
  }

#define Graph vector<vector<int>>
#define PII pair<int, int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int, int>>
#define VS vector<string>
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
#define DDD fixed << setprecision(10)

using namespace std;
/*..................DEFINE GLOBAL VARIABLES...................*/

/*.....................DEFINE FUNCTIONS ......................*/
ll dist(ll x, ll y)
{
  return (x * x) + (y * y);
};

vector<long long> divisor(long long n)
{
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++)
  {
    if (n % i == 0)
    {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end()); // 昇順に並べる
  return ret;
}

/*.........................kemkemG0...........................*/
signed main()
{
  __MAGIC__
  int n, k;
  cin >> n >> k;
  vector<vector<int>> root(n, vector<int>(n));
  rep(i, n)
  {
    rep(j, n)
    {
      cin >> root[i][j];
    };
  };
  vector<int> index;
  rep(i, n) index.push_back(i);

  int ans = 0;
  do
  {
    int time = 0;
    rep(i, n)
    {
      time += root[index[i]][index[(i + 1) % n]];
      if (time == k)
        ans++;
    };
  } while (next_permutation(index.begin() + 1, index.end()));
  co ans en

      return 0;
}
