#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = (long long)1000000007 * 1000000007;
const long double eps = 1e-2;
const long double pi = acos(-1.0);
int n, p;
string s;
int a[17][17];
bool dp[1 << 17];
map<pair<int, pair<int, int> >, bool> used;
int cnt[17];
int ans[1 << 17];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> p;
  cin >> s;
  fill(dp, dp + (1 << p), true);
  for (int i = 0; i < n; i++) {
    cnt[s[i] - 'a']++;
  }
  for (int i = 0; i < p; i++) {
    for (int j = 0; j < p; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < p; i++) {
    for (int j = i + 1; j < p; j++) {
      if (a[i][j]) continue;
      int ca = -1, cb = -1;
      for (int k = 0; k < n; k++) {
        if (s[k] == 'a' + i) {
          ca = k;
        } else if (s[k] == 'a' + j) {
          cb = k;
        } else
          continue;
        if (ca >= 0 && cb >= 0) {
          if (ca < cb) {
            int rec = 0;
            for (int l = ca + 1; l < cb; l++) {
              rec |= (1 << (s[l] - 'a'));
            }
            rec |= (1 << i);
            rec |= (1 << j);
            if (used[{rec, {i, j}}]) {
              ca = -1;
              continue;
            }
            used[{rec, {i, j}}] = true;
            vector<int> v;
            for (int l = 0; l < p; l++) {
              if (rec & (1 << l)) continue;
              v.push_back(l);
            }
            int len = v.size();
            for (int i1 = 0; i1 < (1 << len); i1++) {
              int sum = (1 << i) + (1 << j);
              for (int j1 = 0; j1 < len; j1++) {
                if (i1 & (1 << j1)) {
                  sum += (1 << v[j1]);
                }
              }
              dp[sum] = false;
            }
            ca = -1;
          } else {
            int rec = 0;
            for (int l = cb + 1; l < ca; l++) {
              rec |= (1 << (s[l] - 'a'));
            }
            rec |= (1 << i);
            rec |= (1 << j);
            if (used[{rec, {i, j}}]) {
              cb = -1;
              continue;
            }
            used[{rec, {i, j}}] = true;
            vector<int> v;
            for (int l = 0; l < p; l++) {
              if (rec & (1 << l)) continue;
              v.push_back(l);
            }
            int len = v.size();
            for (int i1 = 0; i1 < (1 << len); i1++) {
              int sum = (1 << i) + (1 << j);
              for (int j1 = 0; j1 < len; j1++) {
                if (i1 & (1 << j1)) {
                  sum += (1 << v[j1]);
                }
              }
              dp[sum] = false;
            }
            cb = -1;
          }
        }
      }
    }
  }
  for (int i = 0; i < p; i++) {
    if (a[i][i]) continue;
    int loc = -1;
    for (int j = 0; j < n; j++) {
      if (s[j] != 'a' + i) continue;
      if (loc >= 0) {
        int rec = 0;
        for (int l = loc + 1; l < j; l++) {
          rec |= (1 << (s[l] - 'a'));
        }
        rec |= (1 << i);
        if (used[{rec, {i, i}}]) continue;
        used[{rec, {i, i}}] = true;
        vector<int> v;
        for (int l = 0; l < p; l++) {
          if (rec & (1 << l)) continue;
          v.push_back(l);
        }
        int len = v.size();
        for (int i1 = 0; i1 < (1 << len); i1++) {
          int sum = (1 << i);
          for (int j1 = 0; j1 < len; j1++) {
            if (i1 & (1 << j1)) {
              sum += (1 << v[j1]);
            }
          }
          dp[sum] = false;
        }
      }
      loc = j;
    }
  }
  fill(ans + 1, ans + (1 << p), n);
  for (int i = 1; i <= (1 << p) - 1; i++) {
    if (!dp[i]) continue;
    ans[i] = 0;
    for (int j = 0; j < p; j++) {
      if (i & (1 << j)) {
        ans[i] += cnt[j];
      }
    }
    for (int j = 0; j < p; j++) {
      if (i & (1 << j)) {
        int ni = i ^ (1 << j);
        ans[i] = min(ans[i], ans[ni]);
      }
    }
  }
  cout << ans[(1 << p) - 1] << endl;
  return 0;
}
