#include <bits/stdc++.h>
const double pi = acos(-1.0);
const int mod = 1e9 + 7;
const int N = 5e5 + 10;
const long long inf = 1LL << 60;
using namespace std;
int dp[27][27];
char a[N][11];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%s", a[i]);
  for (int i = 1; i <= n; i++) {
    int k = strlen(a[i]);
    int q = a[i][0] - 'a', h = a[i][k - 1] - 'a';
    if (q == h) dp[q][q] += k;
    dp[q][h] = max(dp[q][h], k);
    for (int j = 0; j < 26; j++)
      if (dp[j][q] && !(j == h && h == q))
        dp[j][h] = max(dp[j][h], dp[j][q] + k);
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) ans = max(ans, dp[i][i]);
  printf("%d\n", ans);
  return 0;
}
