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