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