#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1e18 + 7;
const int N = 1e3 + 7;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = 1e-8;
int n, dp[26][26], pd[26][26];
char str[20];
int main() {
  scanf("%d", &n);
  for (int i = (0); i < (26); ++i)
    for (int j = (0); j < (26); ++j) dp[i][j] = -INF;
  for (int _n = (0); _n < (n); ++_n) {
    scanf(" %s", str);
    int L = strlen(str);
    int s = str[0] - 'a', e = str[L - 1] - 'a';
    for (int i = (0); i < (26); ++i)
      for (int j = (0); j < (26); ++j) pd[i][j] = dp[i][j];
    dp[s][e] = max(dp[s][e], L);
    for (int i = (0); i < (26); ++i) dp[i][e] = max(dp[i][e], pd[i][s] + L);
  }
  int ans = 0;
  for (int i = (0); i < (26); ++i) ans = max(ans, dp[i][i]);
  printf("%d", ans);
  return 0;
}
