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

int n, p, A[17][17], cnt[17], cal[1 << 17], res = 0x3f3f3f3f;
bool check[1 << 17], adj[17][17][1 << 17];


void dfs(int mask) {
	// if (cal[mask] == 97) cout << "mask = " << mask << endl;
	for (int i = 0; i != p; ++i) for (int j = 0; j != p; ++j) {
		// if (cal[mask] == 97 && mask & 1 << i && mask & 1 << j && !A[i][j]) cout << "i = " << i << " j = " << j << endl;
		if (mask & 1 << i && mask & 1 << j && !A[i][j] && adj[i][j][((1 << p) - 1) ^ mask]) return;
	}
	res = min(res, cal[mask]);
	for (int i = 0; i != p; ++i) if (mask & 1 << i) dfs(mask ^ 1 << i);
}

int main() {
	string str;
	cin >> n >> p >> str;
	for (int i = 0; i != p; ++i) for (int j = 0; j != p; ++j) cin >> A[i][j];
	vector<int> arr(n);
	for (int i = 0; i != n; ++i) ++cnt[arr[i] = str[i] - 'a'];
	for (int i = 1; i != (1 << p); ++i) cal[i] = cal[i ^ (i & -i)] + cnt[__builtin_ctz(i)];
	for (int i = 0; i != p; ++i) for (int j = 0; j != p; ++j) {
		if (i == j) {
			if (find(arr.begin(), arr.end(), i) == arr.end()) break;
			int k = 0;
			for (auto ite = find(arr.begin(), arr.end(), i) + 1; ite != arr.end(); ++ite) {
				if (i == *ite) {
					adj[i][i][k] = true;
					k = 0;
				}
				else {
					k |= 1 << *ite;
				}
			}
		}
		else {
			auto ite1 = find(arr.begin(), arr.end(), i);
			auto ite2 = find(ite1, arr.end(), j);
			while (ite2 != arr.end()) {
				int k = 0;
				for (auto ite = ite1 + 1; ite != ite2; ++ite) if (i != *ite) k |= 1 << *ite;
				adj[i][j][k] = adj[j][i][k] = true;
				ite1 = find(ite2, arr.end(), i);
				ite2 = find(ite1, arr.end(), j);
			}
		}
	}
	for (int i = 0; i != p; ++i) for (int j = 0; j != p; ++j)
		for (int k = 1; k != (1 << p); ++k) for (int l = 0; l != p; ++l)
			if (k & 1 << l) adj[i][j][k] |= adj[i][j][k ^ 1 << l];
	// for (int i = 0; i != (1 << p); ++i) if (adj[1][5][i]) cout << "bf := " << bitset<10>(i).to_string() << endl;
	// for (int i = 0; i != p; ++i) for (int j = 0; j != p; ++j) {
	// 	cout << "i = " << i << " j = " << j << endl;
	// 	for (int k = 0; k != (1 << p); ++k) cout << bitset<17>(k).to_string() << " := " << adj[i][j][k] << endl;
	// }
	dfs((1 << p) - 1);
	cout << res << endl;
}
