#include <bits/stdc++.h>
using namespace std;
char a, b, str[20];
int n, dp[30][30];
int main() {
  scanf("%d", &n);
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < n; i++) {
    scanf("%s", str);
    int len = strlen(str);
    a = str[0] - 'a';
    b = str[len - 1] - 'a';
    for (int i = 0; i < 26; i++) {
      if (dp[i][a] && dp[i][a] + len > dp[i][b]) dp[i][b] = dp[i][a] + len;
    }
    if (dp[a][b] < len) dp[a][b] = len;
  }
  int ans = -1;
  for (int i = 0; i < 26; i++) ans = max(ans, dp[i][i]);
  printf("%d\n", ans);
  return 0;
}
