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