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