#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const int prime = 9241;
const long double pi = acos(-1.);
char p[500005][11];
int lens[500005];
int dp[30][30];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", p[i]);
    lens[i] = strlen(p[i]);
  }
  for (int i = 0; i < 30; i++)
    for (int j = 0; j < 30; j++) dp[i][j] = -(int)1e9;
  for (int i = 0; i < n; i++) {
    int st = p[i][0] - 'a', fin = p[i][lens[i] - 1] - 'a';
    for (int j = 0; j < 26; j++)
      dp[j][fin] = max(dp[j][fin], dp[j][st] + lens[i]);
    dp[st][fin] = max(lens[i], dp[st][fin]);
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) ans = max(ans, dp[i][i]);
  cout << ans << endl;
}
