#include <bits/stdc++.h>
using namespace std;
int main() {
  int ar[26][26];
  for (int i = 0; i < 26; i++)
    for (int j = 0; j < 26; j++) ar[i][j] = 0;
  int n;
  char str[20];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", str);
    int len = strlen(str);
    int a = str[0] - 'a', b = str[len - 1] - 'a';
    int mx = 0;
    for (int j = 0; j < 26; j++) {
      if (ar[j][a] != 0) ar[j][b] = max(ar[j][b], ar[j][a] + len);
    }
    ar[a][b] = max(ar[a][b], len);
  }
  int sol = 0;
  for (int i = 0; i < 26; i++) sol = max(sol, ar[i][i]);
  printf("%d\n", sol);
  return 0;
}
