#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, F[26][26];
  for (int i = 0; i < 26; i++)
    for (int j = 0; j < 26; j++) F[i][j] = 0;
  char s[20];
  scanf("%d\n", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", &s);
    int u = s[0] - 'a';
    int v = s[strlen(s) - 1] - 'a';
    for (int j = 0; j < 26; j++)
      if (F[j][u] > 0)
        if (F[j][v] < F[j][u] + strlen(s)) F[j][v] = F[j][u] + strlen(s);
    F[u][v] = strlen(s) > F[u][v] ? strlen(s) : F[u][v];
  }
  int res = 0;
  for (int i = 0; i < 26; i++)
    if (F[i][i] > res) res = F[i][i];
  printf("%d\n", res);
  return 0;
}
