#include <bits/stdc++.h>
using namespace std;
int n;
char s[500005][20];
int dp[26][26];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%s", s[i]);
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < n; i++) {
    int len = strlen(s[i]);
    int t1 = s[i][0] - 'a';
    int t2 = s[i][len - 1] - 'a';
    for (int j = 0; j < 26; j++) {
      if (dp[j][t1] != -1) dp[j][t2] = max(dp[j][t2], dp[j][t1] + len);
    }
    dp[t1][t2] = max(dp[t1][t2], len);
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) ans = max(dp[i][i], ans);
  cout << ans << endl;
  return 0;
}
