#include <bits/stdc++.h>
using namespace std;
const int N = 500000, M = 27, inf = (int)1e9;
int s[N + 1], e[N + 1], len[N + 1];
int dp[M + 1];
int n, f;
char tmp[11];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", tmp);
    s[i] = tmp[0] - 'a' + 1;
    e[i] = s[i];
    len[i] = 0;
    for (; tmp[len[i]]; len[i]++) e[i] = tmp[len[i]] - 'a' + 1;
  }
  int ans = 0;
  for (int c = 1; c <= 27; c++) {
    for (int i = 0; i <= 27; i++) dp[i] = -inf;
    dp[c] = 0;
    for (int i = 0; i < n; i++) {
      dp[e[i]] = max(dp[e[i]], dp[s[i]] + len[i]);
    }
    ans = max(ans, dp[c]);
  }
  printf("%d\n", ans);
  return 0;
}
