#include <bits/stdc++.h>
using namespace std;
const int N = 12;
const int inf = 2000000000;
char S[N];
int dp[26][26];
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < 26; j++) {
      dp[i][j] = -inf;
    }
  }
  for (; n; n--) {
    scanf("%s", S);
    char a = S[0] - 'a';
    int len = strlen(S);
    char b = S[len - 1] - 'a';
    for (int i = 0; i < 26; i++) {
      dp[i][b] = max(dp[i][b], dp[i][a] + len);
    }
    dp[a][b] = max(dp[a][b], len);
  }
  int sol = 0;
  for (int i = 0; i < 26; i++) sol = max(sol, dp[i][i]);
  printf("%d\n", sol);
  return 0;
}
