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

signed main(){
    int t = 1; //cin >> t;
    while(t--){
        int n,k; cin >> n >> k;
        int time[n+1][n+1];
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= n; j++)
                cin >> time[i][j];
        vector<int> p;
        for(int i = 2; i <= n; i++)
            p.push_back(i);
        int ans = 0;
        do
        {
            int res = 0;
            int city = 1;
            for(int x:p)
            {
                res += time[city][x];
                city = x;
            }
            res += time[city][1];
            if(res == k)
                ans++;
        } while(next_permutation(p.begin(),p.end()));
        cout << ans;
    }    
}
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<long long>> vvll;
typedef std::vector<bool> vb;
typedef std::vector<std::vector<bool>> vvb;
#define INF 1999999999
#define MODA 1000000007
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define rep1(i,n) for (long long i = 1; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define errvn1(x) cerr << #x <<" "<< x << endl;
#define errvn2(x, y) cerr << #x <<" "<< x <<" "<< #y <<" "<< y << endl;
#define errvn3(x, y, z) cerr << #x <<":"<< x <<" "<< #y <<":"<< y <<" "<< #z <<":"<< z << endl;
#define errvn4(x, y, z, a) cerr << #x <<":"<< x <<" "<< #y <<":"<< y <<" "<< #z <<":"<< z <<" "<< #a <<":"<< a << endl;
#define errop2(x, y) cerr << x <<" "<< y << endl;
#define errop3(x, y, z) cerr << x <<" "<< y <<" "<< z << endl;
#define errop4(x, y, z, a) cerr << x <<" "<< y <<" "<< z <<" "<< a << endl;

ll N, K;
vvll T;
ll ans = 0;

// usage:
// foreach_permutation<long long, long long>(n, [&](vector<long long> ind) {
//   operations here;
// });
template<typename T1 = long long, typename T2 = long long>
void foreach_permutation(T1 n, std::function<void(vector<T2>)> func) {
  vector<T2> indexes(n);
  for (T2 i = 0; i < n; ++i) indexes[i] = i;
  do {
    func(indexes);
  } while (std::next_permutation(indexes.begin(), indexes.end()));
}

int main() {
  cin >> N >> K;
  T.resize(N, vll(N));
  rep(i,N) {
    rep(j,N) {
      cin >> T[i][j];
    }
  }
  
  ans = 0;
  foreach_permutation<long long, long long>(N, [&](vector<long long> ind) {
    ll dist = 0;
    if (ind[0] != 0) return;
    for(ll i=0; i<N-1; ++i) {
      dist += T[ind[i]][ind[i+1]];
      cerr << ind[i];
    }
    cerr << endl;
    dist += T[ind[N-1]][ind[0]];
    if(dist == K) ans++;
  });
  
  cout << ans << endl; 
  return 0;
}

