import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String[] s = new String[n]; for (int i = 0; i < n; i++) { s[i] = sc.next(); } sc.close(); int[] dp = new int[26]; label: for (int i = 0; i < n; i++) { char[] t = s[i].toCharArray(); for (int j = 1; j < t.length; j++) { if (t[j - 1] > t[j]) { continue label; } } int d0 = t[0] - 'a'; int d1 = t[t.length - 1] - 'a'; for (int j = d0; j >= 0; j--) { dp[d1] = Math.max(dp[d1], dp[j] + t.length); } } int ans = 0; for (int i = 0; i < dp.length; i++) { ans = Math.max(ans, dp[i]); } System.out.println(ans); } }