import java.io.*; import java.util.*; public class Main { static ArrayList list = new ArrayList<>(); static int[][] dp; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); for (int i = 0; i < n; i++) { String s = sc.next(); if (check(s)) { list.add(s); } } Collections.sort(list, new Comparator() { public int compare(String s1, String s2) { if (s1.charAt(s1.length() - 1) == s2.charAt(s2.length() - 1)) { return s1.charAt(0) - s2.charAt(0); } else { return s1.charAt(s1.length() - 1) - s2.charAt(s2.length() - 1); } } }); dp = new int[list.size()][26]; System.out.println(dfw(list.size() - 1, 25)); } static boolean check(String s) { char start = 'a'; for (char c : s.toCharArray()) { if (c < start) { return false; } start = c; } return true; } static int dfw(int idx, int alpha) { if (idx < 0) { return 0; } if (dp[idx][alpha] == 0) { String s = list.get(idx); if (s.charAt(s.length() - 1) - 'a' > alpha) { dp[idx][alpha] = dfw(idx - 1, alpha); } else { dp[idx][alpha] = Math.max(dfw(idx - 1, alpha), dfw(idx - 1, s.charAt(0) - 'a') + s.length()); } } return dp[idx][alpha]; } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }