#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
const int maxm = 30;
int len[maxn], dp[maxm][maxm];
char fst[maxn], lst[maxn];
int main() {
  char s[12];
  int n, ans;
  while (scanf("%d", &n) != EOF) {
    ans = 0;
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= n; i++) {
      scanf("%s", s);
      len[i] = strlen(s);
      fst[i] = s[0] - 'a';
      lst[i] = s[len[i] - 1] - 'a';
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < 26; j++) {
        if (dp[j][fst[i]])
          dp[j][lst[i]] = max(dp[j][lst[i]], dp[j][fst[i]] + len[i]);
      }
      dp[fst[i]][lst[i]] = max(dp[fst[i]][lst[i]], len[i]);
    }
    for (int i = 0; i < 26; ++i) ans = max(ans, dp[i][i]);
    printf("%d\n", ans);
  }
  return 0;
}
