#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
const int ALP = 26;
char s[MAXN][11];
int len[MAXN];
int dp[ALP][ALP];
void solve() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", s[i]);
    len[i] = strlen(s[i]);
    s[i][0] -= 'a';
    if (len[i] > 1) s[i][len[i] - 1] -= 'a';
  }
  for (int i = 0; i < n; i++) {
    int l = s[i][0], r = s[i][len[i] - 1];
    for (int j = 0; j < ALP; j++) {
      if (!dp[j][l]) continue;
      dp[j][r] = max(dp[j][r], dp[j][l] + len[i]);
    }
    dp[l][r] = max(dp[l][r], len[i]);
  }
  int ans = 0;
  for (int i = 0; i < ALP; i++) {
    ans = max(ans, dp[i][i]);
  }
  cout << ans;
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
