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