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