#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const double eps = 1e-9;
const int mod = 1e9 + 7;
int n, k, a[17][17], fq[100005];
bool mark[1 << 17], memo[1 << 17][17][17], can[1 << 17];
char s[100005];
void f(int m, int a, int b) {
  if (memo[m][a][b]) return;
  memo[m][a][b] = true;
  mark[m] = true;
  for (int i = 0; i < k; i++)
    if ((m & (1 << i)) && i != a && i != b) f(m ^ (1 << i), a, b);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k >> s;
  for (int i = 0; i < n; i++) fq[s[i] - 'a']++;
  for (int i = 0; i < k; i++)
    for (int j = 0; j < k; j++) cin >> a[i][j];
  for (int i = 0; i < k; i++)
    for (int j = 0; j < k; j++) {
      if (i == j || a[i][j]) continue;
      bool is = false;
      int mask;
      for (int l = 0; l < n; l++) {
        if (!is && s[l] - 'a' != i) continue;
        if (s[l] - 'a' == i) {
          is = true;
          mask = 0;
        } else if (s[l] - 'a' == j) {
          f(((1 << k) - 1) ^ mask, i, j);
          is = false;
        } else
          mask |= (1 << (s[l] - 'a'));
      }
    }
  for (int i = 0; i < k; i++) {
    if (a[i][i]) continue;
    int mask;
    bool is = false;
    for (int j = 0; j < n; j++) {
      if (!is && s[j] - 'a' != i) continue;
      if (s[j] - 'a' == i) {
        if (is) f(((1 << k) - 1) ^ mask, i, i);
        mask = 0;
        is = true;
      } else
        mask |= (1 << (s[j] - 'a'));
    }
  }
  int sol = 1 << 30;
  can[(1 << k) - 1] = true;
  for (int i = (1 << k) - 1; i >= 0; i--) {
    if (mark[i] || !can[i]) continue;
    int tmp = 0;
    for (int j = 0; j < k; j++) {
      if (i & (1 << j)) {
        tmp += fq[j];
        can[i ^ (1 << j)] = true;
      }
    }
    sol = min(sol, tmp);
  }
  cout << sol << '\n';
  return 0;
}
