#include <bits/stdc++.h>
int dp[30][30];
char s[20];
int main() {
  int n, i, j;
  char shou, wei;
  scanf("%d", &n);
  memset(dp, -1, sizeof(dp));
  for (i = 0; i < 30; i++) dp[i][i] = 0;
  for (i = 1; i <= n; i++) {
    scanf("%s", s);
    shou = s[0] - 'a', wei = s[strlen(s) - 1] - 'a';
    int l = strlen(s);
    for (j = 0; j < 26; j++)
      if (dp[j][shou] >= 0 && (dp[j][wei] < dp[j][shou] + l))
        dp[j][wei] = dp[j][shou] + l;
  }
  int ans = 0;
  for (i = 0; i < 26; i++)
    if (ans < dp[i][i]) ans = dp[i][i];
  printf("%d\n", ans);
}
