#include <bits/stdc++.h>
const int N = 500005;
int dp[26][26], now[26];
char str[15];
int main() {
  int n, i, j;
  scanf("%d", &n);
  scanf("%s", str);
  memset(dp, -1, sizeof(dp));
  dp[str[0] - 'a'][str[strlen(str) - 1] - 'a'] = strlen(str);
  int res = 0;
  for (i = 1; i < n; i++) {
    scanf("%s", str);
    memset(now, -1, sizeof(now));
    int len = strlen(str), fr = str[0] - 'a', ed = str[len - 1] - 'a';
    for (j = 0; j < 26; j++) {
      if (dp[j][fr] != -1) now[j] = dp[j][fr] + len;
    }
    if (now[fr] == -1 || now[fr] < len) now[fr] = len;
    for (j = 0; j < 26; j++) {
      if (now[j] != -1 && (dp[j][ed] == -1 || dp[j][ed] < now[j]))
        dp[j][ed] = now[j];
    }
    if (dp[ed][ed] != -1 && res < dp[ed][ed]) res = dp[ed][ed];
  }
  printf("%d\n", res);
  return 0;
}
