#include <bits/stdc++.h>
using namespace std;
const int N = 600000;
int n, l[N], dp[30][30];
char str[100];
int first[N], last[N];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", str);
    first[i] = str[0] - 'a';
    l[i] = strlen(str);
    last[i] = str[l[i] - 1] - 'a';
  }
  memset(dp, 0, sizeof(dp));
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < 26; i++) {
      if (dp[i][first[k]] == 0) continue;
      if (dp[i][first[k]] + l[k] > dp[i][last[k]])
        dp[i][last[k]] = dp[i][first[k]] + l[k];
    }
    if (l[k] > dp[first[k]][last[k]]) dp[first[k]][last[k]] = l[k];
  }
  int ans = 0;
  for (int i = 0; i < 26; i++)
    if (dp[i][i] > ans) ans = dp[i][i];
  printf("%d\n", ans);
  return 0;
}
