#include <bits/stdc++.h>
const double eps = 1e-10;
using namespace std;
using ll = long long;
using ul = unsigned long long;
using PII = pair<int, int>;
const int NN = 2222;
const int NZ = 111000;
const int MM = 151;
const int mask = 1 << 4;
const int need = (1 << 30) - 1;
int n, k, m, s, x, a, b, c, q;
int l, pp, answww;
int dp[322][322];
char ss[11000];
int main() {
  scanf("%d", &n);
  for (int i = 'a'; i <= 'z'; i++) {
    for (int j = 'a'; j <= 'z'; j++) dp[i][j] = -10000000000;
  }
  for (int i = 0; i < n; i++) {
    scanf("%s", &ss);
    int ff = ss[0];
    int se = ss[strlen(ss) - 1];
    dp[ff][ff] = max(dp[ff][ff], 0);
    for (int a = 'a'; a <= 'z'; a++) {
      dp[a][se] = max(dp[a][se], dp[a][ff] + (int)strlen(ss));
    }
  }
  for (int a = 'a'; a <= 'z'; a++) {
    answww = max(answww, dp[a][a]);
  }
  printf("%d\n", answww);
  return 0;
}
