#include <bits/stdc++.h>
char s[10];
unsigned int b[26][26];
int main() {
  for (int i = 0; i < 26 * 26; *(*b + i++) = 0)
    ;
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    int len = strlen(s);
    int l = s[0] - 'a';
    int r = s[len - 1] - 'a';
    for (int k = 0; k < 26; k++)
      if (b[k][l] && b[k][r] < b[k][l] + len) b[k][r] = b[k][l] + len;
    if (!b[l][r] || b[l][r] < len) b[l][r] = len;
  }
  int ans = 0;
  for (int i = 0; i < 26; i++)
    if (b[i][i] > ans) ans = b[i][i];
  printf("%d", ans);
  return 0;
}
