#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3fll;
const int MAX = 2e5 + 5;
const long long MOD = 998244353;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
template <typename T>
inline T abs(T a) {
  return a > 0 ? a : -a;
}
template <class T>
inline void read(T &num) {
  bool start = false, neg = false;
  char c;
  num = 0;
  while ((c = getchar()) != EOF) {
    if (c == '-')
      start = neg = true;
    else if (c >= '0' && c <= '9') {
      start = true;
      num = num * 10 + c - '0';
    } else if (start)
      break;
  }
  if (neg) num = -num;
}
inline int powMM(int a, int b, int M) {
  int ret = 1;
  a %= M;
  while (b) {
    if (b & 1) ret = 1LL * ret * a % M;
    b >>= 1;
    a = 1LL * a * a % M;
  }
  return ret;
}
namespace {
template <class T>
inline int add(int x, T y) {
  x += y;
  if (x >= MOD) x -= MOD;
  return x;
}
template <class T>
inline void addi(int &x, T y) {
  x += y;
  if (x >= MOD) x -= MOD;
}
template <class T>
inline int mul(int x, T y) {
  return 1LL * x * y % MOD;
}
template <class T>
inline void muli(int &x, T y) {
  x = 1LL * x * y % MOD;
}
template <class T>
inline int sub(int x, T y) {
  int res = x - y;
  if (res < 0) res += MOD;
  return res;
}
template <class T>
inline void subi(int &x, T y) {
  x -= y;
  if (x < 0) x += MOD;
}
template <class T>
inline int half(int x) {
  return x & 1 ? (x + MOD) >> 1 : x >> 1;
}
}  // namespace
int n, p, tot, ans;
bool ilg[(1 << 17) | 5], pos[(1 << 17) | 5], tem[(1 << 17) | 5];
int a[20][20], dp[(1 << 17) | 5], b[MAX];
char s[MAX];
vector<int> tmv;
void update(int st, int x, int y) {
  assert(st & (1 << x));
  assert(st & (1 << y));
  if (tem[st]) return;
  if (!ilg[st]) {
    ilg[st] = tem[st] = 1;
    tmv.emplace_back(st);
  }
  if (!tem[st]) {
    tmv.emplace_back(st);
    tem[st] = 1;
  }
  for (int i = 0; i < p; i++) {
    if (i == x || i == y) continue;
    if (st & (1 << i)) update(st ^ (1 << i), x, y);
  }
  return;
}
void solve(int x, int y) {
  int lo = -1, st = tot - 1;
  for (int i = 0; i < n; i++) {
    if (b[i] == y && lo != -1) {
      update(st, x, y);
      lo = -1;
    }
    if (b[i] == x) {
      lo = i;
      st = tot - 1;
    }
    if (b[i] != x && b[i] != y && (st & (1 << b[i]))) st ^= (1 << b[i]);
  }
  for (int u : tmv) tem[u] = 0;
  tmv.clear();
}
int main() {
  read(n);
  read(p);
  tot = (1 << p);
  scanf("%s", s);
  for (int i = 0; i < n; i++) ++dp[1 << (b[i] = s[i] - 'a')];
  for (int i = 0; i < p; i++)
    for (int j = 0; j < p; j++) read(a[i][j]);
  for (int i = 0; i < p; i++)
    for (int j = 0; j < p; j++)
      if (!a[i][j]) solve(i, j);
  ans = n;
  pos[tot - 1] = 1;
  for (int i = tot - 1; i > 0; i--) {
    if (!pos[i]) continue;
    for (int j = 0; j < p; j++) {
      if (i & (1 << j)) {
        int nxt = i ^ (1 << j);
        if (!ilg[nxt]) pos[nxt] = 1;
      }
    }
  }
  for (int i = 0; i < tot; i++) {
    if (i) dp[i] = dp[i ^ (i & -i)] + dp[i & -i];
    if (pos[i]) ans = min(ans, dp[i]);
  }
  printf("%d\n", ans);
  return 0;
}
