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