#include <bits/stdc++.h>
using namespace std;
const int N = 2222;
const int mod = 1e9 + 7;
int n;
long long dp[26][26];
char s[11];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("\n%s", s);
    long long k = strlen(s);
    long long fi = s[0] - 'a', se = s[k - 1] - 'a';
    for (int j = 0; j < 26; ++j)
      if (dp[j][fi] > 0) dp[j][se] = max(dp[j][se], dp[j][fi] + k);
    dp[fi][se] = max(dp[fi][se], k);
  }
  long long ans = 0;
  for (int i = 0; i < 26; ++i) ans = max(ans, dp[i][i]);
  cout << ans;
  return 0;
}
