#include <bits/stdc++.h>
using namespace std;
int w[17][17];
char s[100002];
int num[17];
int seg[100002 * 4];
void init(int pos, int l, int r) {
  if (l == r) {
    seg[pos] |= (1 << (s[l] - 'a'));
    return;
  }
  int mid = (l + r) / 2;
  init(pos * 2, l, mid);
  init(pos * 2 + 1, mid + 1, r);
  seg[pos] = seg[pos * 2] | seg[pos * 2 + 1];
}
int query(int pos, int l, int r, int ql, int qr) {
  if (r < ql || qr < l) {
    return 0;
  }
  if (ql <= l && r <= qr) {
    return seg[pos];
  }
  int mid = (l + r) / 2;
  return query(pos * 2, l, mid, ql, qr) |
         query(pos * 2 + 1, mid + 1, r, ql, qr);
}
int lastInd[17];
bool blocked[(1 << 17)];
int dfs(int bit, int p) {
  int ret = 0;
  for (int i = 0; i < p; ++i) {
    if ((bit & (1 << i)) == 0) {
      ret += num[i];
    }
  }
  blocked[bit] = true;
  for (int i = 0; i < p; ++i) {
    if ((bit & (1 << i)) == 0 && !blocked[bit | (1 << i)]) {
      ret = min(ret, dfs(bit | (1 << i), p));
    }
  }
  return ret;
}
int g[17][17][(1 << 17)];
void solve() {
  int n, p;
  scanf("%d %d ", &n, &p);
  scanf(" %s ", s + 1);
  for (int i = 0; i < p; ++i) {
    for (int j = 0; j < p; ++j) scanf("%d ", &w[i][j]);
  }
  init(1, 1, n);
  for (int i = n; i; --i) {
    ++num[s[i] - 'a'];
  }
  for (int i = 0; i < p; ++i) {
    lastInd[i] = -1;
  }
  for (int ind = n; ind; --ind) {
    int alp = s[ind] - 'a';
    if (lastInd[alp] == -1) {
      int x, y;
      for (int i = 0; i < p; ++i) {
        if (w[alp][i] == 0 && lastInd[i] != -1) {
          x = alp, y = i;
          if (x > y) swap(x, y);
          g[x][y][query(1, 1, n, ind + 1, lastInd[i] - 1)] = true;
        }
      }
    } else {
      int lim = lastInd[alp];
      if (w[alp][alp] == 0) {
        g[alp][alp][query(1, 1, n, ind + 1, lim - 1)] = true;
      }
      int x, y;
      for (int i = 0; i < p; ++i) {
        if (w[alp][i] == 0 && lastInd[i] != -1 && lastInd[i] < lim) {
          x = alp, y = i;
          if (x > y) swap(x, y);
          g[x][y][query(1, 1, n, ind + 1, lastInd[i] - 1)] = true;
        }
      }
    }
    lastInd[alp] = ind;
  }
  int lim = (1 << p);
  for (int x = 0; x < p; ++x) {
    for (int y = x; y < p; ++y) {
      if (w[x][y]) {
        continue;
      }
      for (int bit = 0; bit < lim; ++bit) {
        if (g[x][y][bit]) {
          for (int k = 0; k < x; ++k) {
            g[x][y][bit | (1 << k)] = true;
          }
          for (int k = x + 1; k < y; ++k) {
            g[x][y][bit | (1 << k)] = true;
          }
          for (int k = y + 1; k < p; ++k) {
            g[x][y][bit | (1 << k)] = true;
          }
          blocked[bit] = true;
        }
      }
    }
  }
  assert(!blocked[0]);
  int ret = dfs(0, p);
  printf("%d\n", ret);
}
int main() {
  solve();
  return 0;
}
