import java.io.*;
import java.util.*;

public class Maarten {
    public static void main(String[] args) throws IOException {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            new Maarten().run(reader);
        }
    }

    public void run(BufferedReader reader) throws IOException {
        String[] firstLine = reader.readLine().split(" ");
        int n = Integer.parseInt(firstLine[0]);
        int l = Integer.parseInt(firstLine[1]);

        String[] names = new String[n + 2];
        for (int i = 1; i <= n; i++) {
            names[i] = reader.readLine();
        }
        names[0] = names[n + 1] = " ".repeat(l);
        Arrays.sort(names, 1, n + 1);

        int sum = 0;
        for (int j = 1; j <= n; j++) {
            int max = 0;
            for (int k = 0; k < 2; k++) {
                for (int c = 0; c < l; c++) {
                    if (names[j + k - 1].charAt(c) != names[j + k].charAt(c)) {
                        max = Math.max(max, c + 1);
                        break;
                    }
                }
            }
            sum += max;
        }
        System.out.println(sum);
    }
}
