#include <bits/stdc++.h>
using namespace std;
int n, f[27][27], ans = 0;
char ch[15];
int main() {
  scanf("%d", &n);
  memset(f, 0, sizeof(f));
  while (n--) {
    scanf("%s", ch);
    int len = strlen(ch);
    int l = int(ch[0] - 'a' + 1), r = int(ch[len - 1] - 'a' + 1);
    for (int i = 1; i <= 26; i++)
      if (f[i][l]) f[i][r] = max(f[i][r], f[i][l] + len);
    f[l][r] = max(f[l][r], len);
  }
  for (int i = 1; i <= 26; i++) ans = max(ans, f[i][i]);
  printf("%d", ans);
  return 0;
}
