package bj.gold.l4;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.util.StringTokenizer;
public class BJ_G4_1062_가르침 {
static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
static int N;// 단어의 개수 N은 50보다 작거나 같은 자연수이고
static int K;// 배울 알파벳 수 K는 26보다 작거나 같은 자연수 또는 0
static int status;
static int Max;
static int[] wrodBits;
public static void main(String[] args) throws IOException {
input = new BufferedReader(new StringReader(src));
StringTokenizer tokens = new StringTokenizer(input.readLine(), " ");
N = Integer.parseInt(tokens.nextToken()); //
K = Integer.parseInt(tokens.nextToken());
wrodBits = new int[N];
for (int i = 0; i < N; i++) {
wrodBits[i] = wordToBit(input.readLine());
}
// System.out.println("비트 변환 확인: "+Arrays.toString(strs));
// a,n,t,i,c를 못배우면 읽을 수 있는게 전무
if (K < 5) {
System.out.println(0);
return;
}
// antic 배우기
status = wordToBit("antic");
// System.out.println("상태 확인: "+status);
String other = "bdefghjklmopqrsuvwxyz"; // antic를 제외한 나머지 알파벳 - 누구를 배울 것인가? 순서 무관 --> 조합 문제
// 읽을 수 있는 최대 개수
Max = Integer.MIN_VALUE;
makeCombination(other, K - 5, 0, status);
System.out.println(Max == Integer.MIN_VALUE ? 0 : Max);
}
static void makeCombination(String src, int r, int si, int status) {
if (r == 0) {
// 다 뽑았다면 체크해보기
// System.out.println(Integer.toBinaryString(status));
int cnt = 0;
for (int wordBit : wrodBits) {
// 단어인 wordBit를 읽으려면 status에 모든 내용이 있어야 가능
if ((wordBit | status) == status) {
cnt++;
}
}
Max = Math.max(cnt, Max);
return;
}
for (int i = si; i < src.length(); i++) {
char c = src.charAt(i);
// 이미 읽을 수 있으면 생략
if (canRead(status, c)) {
continue;
}
makeCombination(src, r - 1, i, learn(status, c));
}
}
static int learn(int status, char c) {
return status | 1 << (c - 'a');
}
static boolean canRead(int status, char c) {
return (status & 1 << (c - 'a')) > 0;
}
static int wordToBit(String src) {
int status = 0;
for (int i = 0; i < src.length(); i++) {
status = learn(status, src.charAt(i));
}
return status;
}
static boolean check(int status, String src) {
for (int i = 0; i < src.length(); i++) {
if (!canRead(status, src.charAt(i))) {
return false;
}
}
return true;
}
private static String src = "3 6\r\n" +
"antarctica\r\n" +
"antahellotica\r\n" +
"antacartica";
}