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