#include <bits/stdc++.h>
#define int long long
using namespace std;
long long a;
long long n, m;
long long s=0;
vector <int> dd;
void xy(long long r, vector <vector <int>> &qw, vector <vector <int>> &as, long long e, long long d, vector <int> &dd)
{
    if (r!=n+1)
    {
        for (int i=0; i<qw[e].size(); ++i)
        {
            dd[r-1]=e;
            xy(r+1, qw, as, qw[e][i], d+as[e][i], dd);
        }
    }
    else if (e==0 && d==m)
    {
        int y=0;
        vector <int> ff(n);
        for (int i=0; i<n; ++i)
        {
            ff[i]=dd[i];
        }
        sort(ff.begin(), ff.end());
        for (int i=1; i<n; ++i)
            if (ff[i]==ff[i-1])
                y=1;
        if (y==0)
            s+=1;
    }
}
signed main ()
{
    cin >> n >> m;
    vector <vector <int>> qw (n);
    vector <vector <int>> as (n);
    for (int i=0; i<n; ++i)
    {
        for (int ii=0; ii<n; ++ii)
        {
            int f;
            cin >> f;
            qw[i].push_back(ii);
            as[i].push_back(f);
        }
    }
    for (int i=0; i<n; ++i)
        dd.push_back(0);
    a=n;
    xy(1, qw, as, 0, 0, dd);
    cout << s << endl;
}

#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
int main() {
	int n, k;
	cin >> n >> k;
	int cost[n + 1][n + 1];
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			cin >> cost[i][j];
	vector <int> vec;
	for (int i = 1; i <= n; ++i)
		vec.pb(i);
	vec.pb(1);
	int cnt = 0;
	do {
		int tot = 0;
		for (int i = 0; i < n; ++i)
			tot += cost[vec[i]][vec[i + 1]];
		if (tot == k)
			++cnt;
	} while (next_permutation(vec.begin() + 1, vec.begin() + n));
	cout << cnt << endl;
}