#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 2500 + 10;
const int MOD = 199999;
int dp[30][30];
char str[20];
int main() {
  for (int i = 0; i < 26; ++i) {
    for (int j = 0; j < 26; ++j) {
      dp[i][j] = -INF;
    }
  }
  int n, ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", str);
    int len = strlen(str);
    int tou = str[0] - 'a';
    int wei = str[len - 1] - 'a';
    for (int j = 0; j < 26; ++j) {
      dp[wei][j] = max(dp[wei][j], dp[tou][j] + len);
    }
    dp[wei][tou] = max(len, dp[wei][tou]);
  }
  for (int i = 0; i < 26; ++i) {
    ans = max(ans, dp[i][i]);
  }
  printf("%d\n", ans);
  return 0;
}
