#include <bits/stdc++.h>
using namespace std;
struct node {
  int from, to, len;
} edge[500050];
int main() {
  int sum[26][26];
  memset(sum, 0, sizeof(sum));
  int n;
  scanf("%d", &n);
  getchar();
  char str[20];
  for (int i = 0; i < n; ++i) {
    gets(str);
    edge[i].len = strlen(str);
    edge[i].from = str[edge[i].len - 1] - 'a';
    edge[i].to = str[0] - 'a';
  }
  int nh, ne;
  for (int i = n - 1; i >= 0; --i) {
    nh = edge[i].to;
    ne = edge[i].from;
    for (int j = 0; j < 26; ++j) {
      if (sum[ne][j]) sum[nh][j] = max(sum[nh][j], edge[i].len + sum[ne][j]);
    }
    sum[nh][ne] = max(edge[i].len, sum[nh][ne]);
  }
  int maxlen = -1;
  for (int i = 0; i < 26; ++i) {
    maxlen = max(maxlen, sum[i][i]);
  }
  printf("%d", maxlen);
}
