#include <bits/stdc++.h>
using namespace std;
int n, nx;
char s[500001][15];
int l[500001], maxl[30][30], sol = 0;
vector<int> end[30];
int main() {
  scanf("%d", &n);
  int ini, fin;
  for (int i = 0; i < n; i++) {
    scanf("%s", s[i]);
    l[i] = strlen(s[i]);
    ini = s[i][0] - 'a';
    fin = s[i][l[i] - 1] - 'a';
    for (int j = 'a'; j <= 'z'; j++) {
      if (maxl[j - 'a'][ini])
        maxl[j - 'a'][fin] = max(maxl[j - 'a'][fin], maxl[j - 'a'][ini] + l[i]);
    }
    maxl[ini][fin] = max(maxl[ini][fin], l[i]);
  }
  for (int j = 'a'; j <= 'z'; j++) sol = max(sol, maxl[j - 'a'][j - 'a']);
  printf("%d\n", sol);
  return 0;
}
