You are given a string of length n. Each character is one of the first p lowercase Latin letters.

You are also given a matrix A with binary values of size p × p. This matrix is symmetric (A_{ij} = A_{ji}). A_{ij} = 1 means that the string can have the i-th and j-th letters of Latin alphabet adjacent.

Let's call the string crisp if all of the adjacent characters in it can be adjacent (have 1 in the corresponding cell of matrix A).

You are allowed to do the following move. Choose any letter, remove all its occurrences and join the remaining parts of the string without changing their order. For example, removing letter 'a' from "abacaba" will yield "bcb".

The string you are given is crisp. The string should remain crisp after every move you make.

You are allowed to do arbitrary number of moves (possible zero). What is the shortest resulting string you can obtain?

Input

The first line contains two integers n and p (1 ≤ n ≤ 10^5, 1 ≤ p ≤ 17) — the length of the initial string and the length of the allowed prefix of Latin alphabet.

The second line contains the initial string. It is guaranteed that it contains only first p lowercase Latin letters and that is it crisp. Some of these p first Latin letters might not be present in the string.

Each of the next p lines contains p integer numbers — the matrix A (0 ≤ A_{ij} ≤ 1, A_{ij} = A_{ji}). A_{ij} = 1 means that the string can have the i-th and j-th letters of Latin alphabet adjacent.

Output

Print a single integer — the length of the shortest string after you make arbitrary number of moves (possible zero).

Examples

Input


7 3
abacaba
0 1 1
1 0 0
1 0 0


Output


7


Input


7 3
abacaba
1 1 1
1 0 0
1 0 0


Output


0


Input


7 4
bacadab
0 1 1 1
1 0 0 0
1 0 0 0
1 0 0 0


Output


5


Input


3 3
cbc
0 0 0
0 0 1
0 1 0


Output


0

Note

In the first example no letter can be removed from the initial string.

In the second example you can remove letters in order: 'b', 'c', 'a'. The strings on the intermediate steps will be: "abacaba" → "aacaa" → "aaaa" → "".

In the third example you can remove letter 'b' and that's it.

In the fourth example you can remove letters in order 'c', 'b', but not in the order 'b', 'c' because two letters 'c' can't be adjacent.
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.TreeSet;

@SuppressWarnings("unchecked")
public class F {
	
	int n, p;
	char[] s;
	boolean[][] adj;
	ArrayList<Integer>[][] badMasks;
	int[] cnt;
	int[] memo;
	int[] memoLen;
	
	int len(int mask) {
		if(memoLen[mask] != -1) return memoLen[mask];
		int ans = n;
		for(int i = 0; i < p; ++i) if((mask & (1 << i)) == 0) ans -= cnt[i];
		return memoLen[mask] = ans;
	}
	
	int go(int mask) {
		if(memo[mask] != -1) return memo[mask];
		int inv = ~mask;
		int ans = n;
		boolean good = true;
		for(int i = 0; good && i < p; ++i) {
			if((mask & (1 << i)) == 0) continue;
			for(int j = i; good && j < p; ++j) {
				if((mask & (1 << j)) == 0) continue;
				for(int bad : badMasks[i][j]) {
					if((bad & inv) == bad) {
						good = false;
						break;
					}
				}
			}
		}
		if(good) {
			ans = Math.min(ans, len(mask));
			for(int i = 0; i < p; ++i) {
				if((mask & (1 << i)) == 0) continue;
				ans = Math.min(ans, go(mask - (1 << i)));
			}
		}
		return memo[mask] = ans;
	}
	
//	int go(int mask) {
//		if(memo[mask] != -1) return memo[mask];
//		int inv = ~mask;
//		int ans = n;
//		if(isGood[mask]) {
//			ans = Math.min(ans, len(mask));
//			for(int i = 0; i < p; ++i) {
//				if((mask & (1 << i)) == 0) continue;
//				ans = Math.min(ans, go(mask - (1 << i)));
//			}
//		}
//		return memo[mask] = ans;
//	}
	
	public void solve(JS in, PrintWriter out) {
		n = in.nextInt();
		p = in.nextInt();
		s = in.next().toCharArray();
		adj = new boolean[p][p];
		cnt = new int[p];
		memoLen = new int[1 << p]; Arrays.fill(memoLen, -1);
		memo = new int[1 << p]; Arrays.fill(memo, -1);
		for(int i = 0; i < p; ++i) {
			for(int j = 0; j < p; ++j) {
				adj[i][j] = in.nextInt() == 1;
			}
		}
		for(int i = 0; i < n; ++i) cnt[s[i] - 'a']++;
		//precomp
		int[] masks = new int[n];
		for(int i = 0; i < n; ++i) masks[i] = 1 << (s[i] - 'a');
		RMQ rmq = new RMQ(masks);
		TreeSet<Integer>[] indexes = new TreeSet[p];
		badMasks = new ArrayList[p][p];
		for(int i = 0; i < p; ++i) indexes[i] = new TreeSet<>();
		for(int i = 0; i < n; ++i) indexes[s[i] - 'a'].add(i);
		for(int i = 0; i < p; ++i) for(int j = 0; j < p; ++j) badMasks[i][j] = new ArrayList<>();
		for(int i = 0; i < n; ++i) {
			int c1 = s[i] - 'a';
			for(int c2 = 0; c2 < p; ++c2) { //next thing after me
				if(adj[c1][c2]) continue;
				Integer j = indexes[c2].higher(i);
				if(j == null) continue;
				int middleMask = rmq.query(i + 1, j - 1);
				badMasks[c1][c2].add(middleMask);
				badMasks[c2][c1].add(middleMask);
			}
		}
		for(int i = 0; i < p; ++i) {
			for(int j = 0; j < p; ++j) {
				Collections.sort(badMasks[i][j], (a, b) -> Integer.bitCount(a) - Integer.bitCount(b));
			}
		}
		out.println(go((1 << p) - 1));
	}
	
	public static void main(String[] args) {
		JS in = new JS();
		PrintWriter out = new PrintWriter(System.out);
		new F().solve(in, out);
		out.close();
	}
	
	static class RMQ {
		int[] vs;
		int[][] lift;

		public RMQ(int[] vs) {
			this.vs = vs;
			int n = vs.length;
			int maxlog = Integer.numberOfTrailingZeros(Integer.highestOneBit(n)) + 2;
			lift = new int[maxlog][n];
			for (int i = 0; i < n; i++)
				lift[0][i] = vs[i];
			int lastRange = 1;
			for (int lg = 1; lg < maxlog; lg++) {
				for (int i = 0; i < n; i++) {
					lift[lg][i] = lift[lg - 1][i] | lift[lg - 1][Math.min(i + lastRange, n - 1)];
				}
				lastRange *= 2;
			}
		}

		public int query(int low, int hi) {
			if(low > hi) return 0;
			int range = hi - low + 1;
			int exp = Integer.highestOneBit(range);
			int lg = Integer.numberOfTrailingZeros(exp);
			return lift[lg][low] | lift[lg][hi - exp + 1];
		}
	}
	
	static class JS {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public JS() {
			in = new BufferedInputStream(System.in, BS);
		}

		public JS(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
	}
}
