#include <bits/stdc++.h>
using namespace std;
const int maxn = 10000;
int dp[26][26];
int main() {
  int n;
  scanf("%d", &n);
  char ss[20];
  int len, st, ed;
  for (int i = 0; i < n; i++) {
    scanf("%s", ss);
    len = strlen(ss);
    st = ss[0] - 'a';
    ed = ss[len - 1] - 'a';
    for (int i = 0; i < 26; i++) {
      if (dp[i][st]) dp[i][ed] = max(dp[i][ed], dp[i][st] + len);
    }
    if (dp[st][ed] < len) dp[st][ed] = len;
  }
  int ans = 0;
  for (int i = 0; i < 26; i++)
    if (ans < dp[i][i]) ans = dp[i][i];
  printf("%d\n", ans);
  return 0;
}
