#include <bits/stdc++.h>
using namespace std;
bool home = 1;
signed realMain();
signed main() {
  home = 0;
  if (home) {
    freopen("input", "r", stdin);
  } else {
    ios::sync_with_stdio(0);
    cin.tie(0);
  }
  realMain();
}
const long long N = 17;
long long len, n, consec[N][N], ok[1 << N], f[N], tot[1 << N], rl[1 << N],
    last[N];
string s;
bool okp[1 << N];
bitset<1 << N> bad[N][N];
signed realMain() {
  cin >> len >> n >> s;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      cin >> consec[i][j];
    }
  }
  for (long long i = 0; i < (1 << n); i++) {
    ok[i] = 1;
  }
  for (long long i = 0; i < len; i++) {
    long long x = s[i] - 'a';
    f[x]++;
  }
  for (long long i = 0; i < n; i++) {
    last[i] = -1;
  }
  for (long long i = 0; i < len; i++) {
    long long x = s[i] - 'a';
    for (long long y = 0; y < n; y++) {
      if (last[y] != -1) {
        if (consec[x][y]) continue;
        long long pos = last[y];
        if (pos < last[x]) {
          continue;
        }
        long long mid = 0;
        for (long long z = 0; z < n; z++) {
          if (z == x || z == y) continue;
          if (pos < last[z]) {
            mid |= (1 << z);
          }
        }
        mid = (1 << n) - 1 - mid;
        assert(mid & (1 << x));
        assert(mid & (1 << y));
        bad[x][y][mid] = 1;
      }
    }
    last[x] = i;
  }
  for (long long i = 0; i < n; i++) {
    tot[1 << i] = f[i];
  }
  for (long long i = 1; i < (1 << n); i++) {
    long long j = i & (-i);
    tot[i] = tot[j] + tot[i ^ j];
  }
  for (long long x = 0; x < n; x++) {
    for (long long y = 0; y < n; y++) {
      if (consec[x][y]) continue;
      for (long long bit = 0; bit < n; bit++) {
        if (bit == x || bit == y) continue;
        for (long long i = 0; i < (1 << n); i++) {
          if (i & (1 << bit) && bad[x][y][i]) {
            bad[x][y][i ^ (1 << bit)] = 1;
          }
        }
      }
    }
  }
  for (long long i = 0; i < (1 << n); i++) {
    for (long long x = 0; x < n; x++) {
      for (long long y = 0; y < n; y++) {
        ok[i] &= !bad[x][y][i];
      }
    }
  }
  rl[(1 << n) - 1] = 1;
  for (long long i = (1 << n) - 1; i >= 0; i--) {
    rl[i] &= ok[i];
    if (!rl[i]) continue;
    for (long long bit = 0; bit < n; bit++) {
      if (i & (1 << bit)) {
      }
    }
    for (long long bit = 0; bit < n; bit++) {
      if (i & (1 << bit)) {
        rl[i ^ (1 << bit)] |= 1;
      }
    }
  }
  long long ret = (long long)1e9;
  for (long long i = 0; i < (1 << n); i++) {
    if (rl[i]) {
      ret = min(ret, tot[i]);
    }
  }
  cout << ret << "\n";
  return 0;
}
