#include<iostream>
using namespace std;
#include<vector>
#include <algorithm>
#include <bits/stdc++.h>
#define re(i,n) for(int i = 0; i < n; i++)
const int MOD = 998244353;

int main(){
    int n, k;
    cin >> n >> k;
    int array[n-1];
    re(i, n - 1) array[i] = i+ 1;
    vector<vector<int>> t(n, vector<int>(n));
    re(i,n){
        re(j,n) cin >> t[i][j];
    }
    int cnt = 0;
    do{ int sum = t[0][array[0]];;
        for(int i=0; i<n-2; i++){
           sum += t[array[i]][array[i+1]];
        }
        sum+=t[array[n-2]][0];
        if(sum == k) cnt++;
    }while(next_permutation(array,array+n-1));
    cout << cnt << endl;;
}

#include<bits/stdc++.h>
#define fastio  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define printara(ara, n) for(int i = 0; i < n; i++) cout << ara[i] << ' '; cout << endl;
#define printvec(vec) for(auto it : vec) cout << it << ' '; cout << endl;
#define debug(x) cout << #x << "--> " << x << endl;
#define int long long
#define pii pair<int, int>
#define ff first
#define ss second
using namespace std;
int n, m, k, cost[10][10], vis[10];
int solve(int i, int sum, bool isfirst)
{
	if (i == 1 && !isfirst)
	{
		if (sum == k) return 1;
		else return 0;
	}
	int ans = 0;
	for (int j = 1; j <= n; j++)
	{
		if (i != j && vis[j] == false)
		{
			vis[j] = true;
			ans += solve(j, sum + cost[i][j], false);
			vis[j] = false;
		}
	}
	return ans;
}
main()
{
	fastio;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++) cin >> cost[i][j];
	}
	int ans = solve(1, 0, true);
	cout << ans << endl;
}
