#include <bits/stdc++.h>
using namespace std;
int n, pocz, kon;
int dp[100][100];
char s[100];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (26); i++)
    for (int j = 0; j < (26); j++) dp[i][j] = -1;
  for (int i = 0; i < (26); i++) dp[i][i] = 0;
  for (int i = 0; i < (n); i++) {
    scanf(" %s", s);
    pocz = s[0] - 'a';
    kon = s[strlen(s) - 1] - 'a';
    for (int i = 0; i < (26); i++)
      if (dp[i][pocz] >= 0)
        dp[i][kon] = max(dp[i][kon], dp[i][pocz] + (int)strlen(s));
  }
  int res = 0;
  for (int i = 0; i < (26); i++) res = max(res, dp[i][i]);
  printf("%d\n", res);
  return 0;
}
