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