#include <bits/stdc++.h>
using namespace std;
int dp[26][26];
int main() {
  char name[20], s, e;
  int n, i, j, len, maxi;
  scanf("%d", &n);
  for (int i = (int)0; i < (int)n; ++i) {
    scanf("%s", name);
    len = strlen(name);
    s = name[0];
    e = name[len - 1];
    maxi = len;
    for (j = 0; j < 26; j++) {
      if (dp[j][s - 97] > 0 && dp[j][s - 97] + len > dp[j][e - 97])
        dp[j][e - 97] = dp[j][s - 97] + len;
    }
    if (maxi > dp[s - 97][e - 97]) dp[s - 97][e - 97] = maxi;
  }
  int ans = 0;
  for (i = 0; i < 26; i++)
    if (dp[i][i] > ans) ans = dp[i][i];
  printf("%d\n", ans);
  return 0;
}
