#include <bits/stdc++.h>
using namespace std;
template <class T>
using vv = vector<vector<T>>;
template <class T>
ostream &operator<<(ostream &os, const deque<T> &t) {
  os << "{";
  for (int(i) = 0; (i) < (t.size()); ++(i)) {
    os << t[i] << ",";
  }
  os << "}" << endl;
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &t) {
  os << "{";
  for (int(i) = 0; (i) < (t.size()); ++(i)) {
    os << t[i] << ",";
  }
  os << "}" << endl;
  return os;
}
template <class T, size_t n>
ostream &operator<<(ostream &os, const array<T, n> &t) {
  os << "{";
  for (int(i) = 0; (i) < (n); ++(i)) {
    os << t[i] << ",";
  }
  os << "}" << endl;
  return os;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &t) {
  return os << "(" << t.first << "," << t.second << ")";
}
template <class S, class T, class U>
ostream &operator<<(ostream &os, const tuple<S, T, U> &t) {
  return os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
}
template <class S, class T, class U, class V>
ostream &operator<<(ostream &os, const tuple<S, T, U, V> &t) {
  return os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ","
            << get<3>(t) << ")";
}
template <class S, class T, class U, class V, class W>
ostream &operator<<(ostream &os, const tuple<S, T, U, V, W> &t) {
  return os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ","
            << get<3>(t) << "," << get<4>(t) << ")";
}
template <class T>
inline bool MX(T &l, const T &r) {
  return l < r ? l = r, 1 : 0;
}
template <class T>
inline bool MN(T &l, const T &r) {
  return l > r ? l = r, 1 : 0;
}
const long long MOD = 1e9 + 7;
int A[18][18];
int ng[1 << 17][18];
int main() {
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(0);
  int n, p;
  string s;
  cin >> n >> p >> s;
  vector<int> cnt(p);
  for (char c : s) ++cnt[c - 'a'];
  for (int(i) = 0; (i) < (p); ++(i))
    for (int(j) = 0; (j) < (p); ++(j)) cin >> A[i][j];
  vector<int> nxt(p, n);
  vector<int> ind(p);
  iota((ind).begin(), (ind).end(), 0);
  for (int(i) = (n)-1; (i) >= 0; --(i)) {
    int x = s[i] - 'a';
    sort((ind).begin(), (ind).end(),
         [&](int i, int j) { return nxt[i] < nxt[j]; });
    int st = 0;
    (i, ind, 1);
    for (int j : ind) {
      if (nxt[j] == n) break;
      if (!A[x][j]) {
        ng[st][x] |= 1 << j;
        ng[st][j] |= 1 << x;
      }
      (i, j, x, A[x][j], st, 1);
      st |= 1 << j;
    }
    nxt[x] = i;
  }
  vector<int> ok(1 << p);
  for (int(i) = 0; (i) < (1 << p); ++(i)) {
    int f = 1;
    int c = ((1 << p) - 1) ^ i;
    for (int j = c;; j = (j - 1) & c) {
      for (int(a) = 0; (a) < (p); ++(a))
        if (i >> a & 1) {
          if (ng[j][a] & i) {
            f = 0;
            break;
          }
        }
      if (j == 0) break;
      if (!f) break;
    }
    ok[i] = f;
  }
  (ok, 1);
  vector<int> vst(1 << p);
  queue<int> que;
  que.emplace((1 << p) - 1);
  vst[(1 << p) - 1] = 1;
  int re = n;
  while (que.size()) {
    int st = que.front();
    que.pop();
    int sum = 0;
    for (int(i) = 0; (i) < (p); ++(i))
      if (st >> i & 1) sum += cnt[i];
    MN(re, sum);
    for (int(i) = 0; (i) < (p); ++(i))
      if (st >> i & 1) {
        int nxt = st ^ (1 << i);
        if (ok[nxt] && MX(vst[nxt], 1)) que.emplace(nxt);
      }
  }
  (ok, vst, 1);
  cout << re << endl;
  return 0;
}
