#include <bits/stdc++.h>
using namespace std;
int dp[26][26];
char ch[500007][12], s[500007], e[500007];
int len[500007];
int n, res;
int main() {
  int i, j;
  scanf("%d", &n);
  for (i = 0; i < 26; i++) {
    for (j = 0; j < 26; j++) {
      dp[i][j] = -1000000000;
    }
  }
  for (i = 0; i < n; i++) {
    scanf("%s", &ch[i]);
    len[i] = strlen(ch[i]);
    s[i] = ch[i][0] - 'a';
    e[i] = ch[i][len[i] - 1] - 'a';
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < 26; j++) {
      dp[j][e[i]] = max(dp[j][e[i]], dp[j][s[i]] + len[i]);
    }
    dp[s[i]][e[i]] = max(dp[s[i]][e[i]], len[i]);
  }
  for (i = 0; i < 26; i++) {
    res = max(res, dp[i][i]);
  }
  cout << res << endl;
  return 0;
}
