import java.math.BigInteger;
import java.util.*;
import java.io.*;

public class Div716 {
    static int[] dp;
    static int[] occ;
    static boolean[] masks;

    static int dp(int m) {
        if (m == (1 << occ.length) - 1)
            return 0;
        if (dp[m] != -1)
            return dp[m];
        int ans = 0;
        for (int i = 0; i < occ.length; i++)
            if ((m & 1 << i) == 0)
                ans += occ[i];

//        System.err.println(ans);
        for (int i = 0; i < occ.length; i++) {
            if ((m & 1 << i) == 0 && !masks[m | 1 << i]) {
                ans = Math.min(ans, dp(m | 1 << i));
            }
        }
        return dp[m] = ans;
    }

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int p = sc.nextInt();
        char[] s = sc.nextLine().toCharArray();

        int[][] a = new int[p][p];
        for (int i = 0; i < p; i++)
            a[i] = sc.nextIntArr(p);
        boolean[][][] preprocess = new boolean[p][p][1 << p];

        masks = new boolean[1 << p];
        int[] ids = new int[p];
        Arrays.fill(ids, -1);
        occ = new int[p];
        for (int i = 0; i < n; i++) {
            int cur = s[i] - 'a';
            for (int j = 0; j < p; j++) {
                if (ids[cur] > ids[j] || ids[j] == -1 || a[cur][j] == 1)
                    continue;
                int mask = 0;
                for (int k = 0; k < p; k++) {
                    if (ids[k] > ids[j])
                        mask |= 1 << k;
                }
                preprocess[cur][j][mask] = true;
                preprocess[j][cur][mask] = true;
//                System.err.println(Integer.toBinaryString(mask) + " " + cur + " " + j + " " + i);
            }
            ids[cur] = i;
            occ[cur]++;
        }
        for (int l = 0; l < p; l++)
            for (int k = 0; k < p; k++)
                for (int i = 0; i < 1 << p; i++) {
                    masks[i] |= preprocess[l][k][i];
                    for (int j = 0; j < p; j++) {
                        if (j != k && j != l)
                            preprocess[l][k][i | 1 << j] |= preprocess[l][k][i];
                    }
                }
//        System.err.println(Arrays.toString(masks));
        dp = new int[1 << p];
        Arrays.fill(dp,-1);
        pw.println(dp(0));
        pw.flush();
    }


    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int[] nextIntArr(int n) throws IOException {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}