import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int length = sc.nextInt(); char[][] inputs = new char[n][]; ArrayList list = new ArrayList<>(); for (int i = 0; i < n; i++) { inputs[i] = sc.next().toCharArray(); for (int j = 0; j < i; j++) { list.add(new Path(i, j, getDistance(inputs[i], inputs[j]))); } } Collections.sort(list); UnionFindTree uft = new UnionFindTree(n); int ans = 0; for (Path p : list) { if (!uft.same(p)) { ans += p.value; uft.unite(p); } } System.out.println(ans); } static int getDistance(char[] s, char[] t) { int distance = 0; for (int i = 0; i < s.length; i++) { if (s[i] != t[i]) { distance++; } } return distance; } static class Path implements Comparable { int left; int right; int value; public Path(int left, int right, int value) { this.left = left; this.right = right; this.value = value; } public int compareTo(Path another) { return value - another.value; } } static class UnionFindTree { int[] parents; public UnionFindTree(int size) { parents = new int[size]; for (int i = 0; i < size; i++) { parents[i] = i; } } public int find(int x) { if (x == parents[x]) { return x; } else { return parents[x] = find(parents[x]); } } public boolean same(int x, int y) { return find(x) == find(y); } public boolean same(Path p) { return same(p.left, p.right); } public void unite(int x, int y) { parents[find(x)] = find(y); } public void unite(Path p) { unite(p.left, p.right); } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }