import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int length = sc.nextInt(); char[][] all = new char[n][]; for (int i = 0; i < n; i++) { all[i] = sc.next().toCharArray(); } PriorityQueue queue = new PriorityQueue<>(); for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { queue.add(new Path(i, j, getCost(all[i], all[j]))); } } UnionFindTree uft = new UnionFindTree(n); long cost = 0; while (queue.size() > 0) { Path p = queue.poll(); if (!uft.same(p)) { uft.unite(p); cost += p.value; } } System.out.println(cost); } static int getCost(char[] a1, char[] a2) { int cost = 0; for (int i = 0; i < a1.length; i++) { if (a1[i] != a2[i]) { cost++; } } return cost; } 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); } } 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; } } }