#include <bits/stdc++.h>
using namespace std;
char name[15];
int dp[27][27];
int n;
int main() {
  while (~scanf("%d", &n)) {
    memset(dp, -1, sizeof(dp));
    int i, j;
    for (i = 0; i < n; i++) {
      scanf("%s", name);
      int len = strlen(name);
      int l = name[0] - 'a', r = name[len - 1] - 'a';
      for (j = 0; j < 26; j++)
        if (dp[j][l] != -1) dp[j][r] = max(dp[j][r], dp[j][l] + len);
      dp[l][r] = max(dp[l][r], len);
    }
    int ans = 0;
    for (i = 0; i < 26; i++) ans = max(ans, dp[i][i]);
    printf("%d\n", ans);
  }
  return 0;
}
