// Arup Guha
// 1/27/2026
// Solution to Kattis Problem: Dance Recital
// https://open.kattis.com/problems/dancerecital

import java.util.*;

public class dancerecital {

	// Stores the routines.
	public static int n;
	public static int[] routines;
	public static int[][] cost;

	public static void main(String[] args) {
	
		// Get # of routines.
		Scanner stdin = new Scanner(System.in);
		n = stdin.nextInt();
		routines = new int[n];
		cost = new int[n][n];
		
		// Store dancers in a routine as a 26 bit bitmask.
		for (int i=0; i<n; i++) {
			char[] tmp = stdin.next().toCharArray();
			
			// Here we set a bit 0 - 25 on if 'A' through 'Z' is the dancer.
			for (int j=0; j<tmp.length; j++)
				routines[i] |= (1<<(tmp[j]-'A'));
		}
		
		// Fill in cost array.
		for (int i=0; i<n; i++) {
			for (int j=0; j<n; j++) {
			
				// Just go through the bits.
				for (int k=0; k<26; k++) {
					if (  (routines[i] & (1<<k)) > 0 && (routines[j] & (1<<k)) > 0 )
						cost[i][j]++;
				}
			}
		}
		
		// Ta da!
		System.out.println(go(new int[n], new boolean[n], 0));
	}
	
	public static int go(int[] perm, boolean[] used, int k) {
		
		// Done filling it in, return # of quick changes.
		if (k == n) return eval(perm);
		
		// Will be overwritten.
		int res = 1000;
		
		// Try each option.
		for (int i=0; i<n; i++) {
			
			// used it already.
			if (used[i]) continue;
			
			// Try it and updat our answer if necessary.
			used[i] = true;
			perm[k] = i;
			res =  Math.min(res, go(perm, used, k+1));
			
			// Undo so we can use later.
			used[i] = false;
		}
		
		// Done.
		return res;
	}
	
	// Returns the cost of this permutation of dance routines.
	public static int eval(int[] perm) {
		int res = 0;
		
		// No point to recompute, just look up in our precomputed array.
		for (int i=0; i<n-1; i++)
			res += cost[perm[i]][perm[i+1]];
		return res;
	}

}