#include <bits/stdc++.h>
using namespace std;
const int Maxn = 5e5 + 10;
struct King {
  int s, t, len;
  char str[13];
} king[Maxn];
int n;
int dp[30][30];
int main() {
  memset(dp, 0, sizeof(dp));
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%s", king[i].str);
    king[i].len = strlen(king[i].str);
    king[i].s = king[i].str[0] - 'a';
    king[i].t = king[i].str[king[i].len - 1] - 'a';
    int s = king[i].s, t = king[i].t;
    for (int j = 0; j < 26; ++j) {
      if (dp[j][s] == 0) continue;
      dp[j][t] = max(dp[j][t], dp[j][s] + king[i].len);
    }
    dp[s][t] = max(dp[s][t], king[i].len);
  }
  int ans = 0;
  for (int i = 0; i < 26; ++i) ans = max(ans, dp[i][i]);
  printf("%d\n", ans);
  return 0;
}
