#include <bits/stdc++.h>
#define watch(x) std::cout << (#x) << " is " << (x) << std::endl
using LL = long long;
using pii = std::pair<int, int>;
using pll = std::pair<LL, LL>;

int main() {
	//freopen("in","r",stdin);
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int n, k;
	std::cin >> n >> k;
	std::vector<std::vector<int>> a(n, std::vector<int>(n)); 
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			std::cin >> a[i][j];
		}
	}
	std::vector<int> p(n - 1);
	std::iota(p.begin(), p.end(), 1);
	auto sum = [&]() {
		LL r = a[0][p[0]];
		for (int i = 0; i + 2 < n; ++i) r += a[p[i]][p[i + 1]];
		return r + a[p.back()][0];
	};
	int r = 0;
	do {
		if (sum() == k) ++r;
	} while (std::next_permutation(p.begin(), p.end()));
	std::cout << r << std::endl;
	return 0;
}
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
using vi  = vector<int>;
using ii  = pair<int,int>;
using vii = vector<ii>;
using ll  = long long;

typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;

#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) int((x).size())
#define REP(i, a, b) for (auto (i) = (a); (i) <= (b); (i)++)
#define PER(i, a, b) for (auto (i) = (a); (i) >= (b); (i)--)
#define ITR(i, x) for (auto (i) = (x).begin(); (i) != (x).end(); (i)++)

ll mod_pow(ll b, ll e, ll m) {
	if (e == 0) return 1 % m;
	if (e == 1) return b % m;
	if (e & 1) return mod_pow(b, e-1, m) * b % m;
	return mod_pow(b*b%m, e/2, m);
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	ll n, m;
	cin >> n >> m;
	cout << mod_pow(10, n, m*m)/m << '\n';
	return 0;
}