#include <bits/stdc++.h>
using namespace std;
double eps = 1e-9;
const int INF = 1e9 + 7;
const int MAXN = int(2e5 + 7);
int n, ans, dp[200][200];
char second[20];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", second);
    int m = strlen(second) - 1;
    for (int j = 'a'; j <= 'z'; j++)
      if (dp[j][second[0]] > 0)
        dp[j][second[m]] = max(dp[j][second[m]], dp[j][second[0]] + m + 1);
    dp[second[0]][second[m]] = max(dp[second[0]][second[m]], m + 1);
  }
  for (int i = 'a'; i <= 'z'; i++) ans = max(ans, dp[i][i]);
  printf("%d\n", ans);
  return 0;
}
