#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD
#define MODSUB(SUB_X,SUB_Y)  ((SUB_X-SUB_Y)+MOD)%MOD
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD
#define LCM(LCM_X,LCM_Y) (LCM_X/__gcd(LCM_X,LCM_Y))*LCM_Y
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
int ans,k,n,cost[60][60];
void recur(int cur,int sum,int tot,int used[])
{
    if(tot==(n-1))
    {
        sum+=cost[cur][1];
        if(k==sum)
            ans++;
        return ;
    }
    for(int i=2; i<=n; i++)
    {
        if(!used[i])
        {
            used[i]=1;
            recur(i,sum+cost[cur][i],tot+1,used);
            used[i]=0;
        }
    }
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    cin>>n>>k;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
            cin>>cost[i][j];
    int used[50]= {0};
    recur(1,0,0,used);
    cout<<ans<<endl;

    return 0;
}

#include<iostream>
#include<vector>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)

const int maxN=10;
vector<vector<int>> T(maxN, vector<int> (maxN, -1));
bool used[maxN];
vector<int> v={0};
int N,K;

int dfs(){
    if(v.size()==N){
        v.push_back(0);
        int sum=0;
        rep(i, N){
            sum += T[v[i]][v[i+1]];
        }
        /*
        rep(i,N+1){
            cout << v[i] << ' ';
        }
        cout << endl;

        cout << sum << endl;
        */
        v.pop_back();

        if(sum==K) return 1;
        else return 0;
    }
    
    int res=0;
    for(int i=1;i<=N-1;i++){
        if(!used[i]){
            v.push_back(i);
            used[i]=true;
            res += dfs();
            used[i]=false;
            v.pop_back();

        }
    }
    return res;
}


int main(){
    cin >> N >> K;
    rep(i,N)rep(j,N) cin >> T[i][j];
    rep(i,N) used[i]=false;

    int res = dfs();

    cout << res << endl;
    return 0;

}



