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