#include <bits/stdc++.h>
using namespace std;
const int maxm = 17;
int last[maxm];
bool f[maxm][maxm][1 << maxm];
int cnt[maxm];
int a[maxm][maxm];
bool disallow[1 << maxm];
bool reachable[1 << maxm];
int getbit(int x, int k) { return (x >> k) & 1; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n = 0;
  cin >> n;
  int k = 0;
  cin >> k;
  string s;
  cin >> s;
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < k; j++) cin >> a[i][j];
  }
  memset(last, -1, sizeof(last));
  for (int i = 0; i < n; i++) {
    int u = s[i] - 'a';
    for (int j = 0; j < k; j++) {
      if (!a[u][j]) {
        int t = last[j];
        if (last[j] == -1) continue;
        int state = 0;
        t++;
        bool ok = true;
        while (t < i) {
          state |= (1 << ((int)(s[t] - 'a')));
          if (s[t] - 'a' == u) ok = false;
          t++;
        }
        if (ok) {
          f[u][j][state] = true;
          f[j][u][state] = true;
        }
      }
    }
    last[u] = i;
  }
  for (int i = 0; i < n; i++) {
    cnt[s[i] - 'a']++;
  }
  for (int i = 0; i < k; i++) {
    for (int j = i; j < k; j++) {
      assert(f[i][j][0] == false);
      for (int cur = 0; cur < (1 << k); cur++) {
        disallow[cur] |= f[i][j][cur];
        if (f[i][j][cur]) {
          for (int l = 0; l < k; l++) {
            if (l == i || l == j) continue;
            if (getbit(cur, l)) continue;
            f[i][j][cur | (1 << l)] = true;
          }
        }
      }
    }
  }
  reachable[0] = true;
  int res = n;
  for (int i = 0; i < (1 << k); i++) {
    if (disallow[i] || !reachable[i]) continue;
    int tmp = 0;
    for (int j = 0; j < k; j++) {
      if (!getbit(i, j)) {
        reachable[i | (1 << j)] = true;
        tmp += cnt[j];
      }
    }
    res = min(res, tmp);
  }
  cout << res;
  return 0;
}
