#include <bits/stdc++.h>
using namespace std;
int n, len[500009], f[2][30][30];
char s[500009][23];
int main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) scanf("%s", s[i]), len[i] = strlen(s[i]);
  f[1][s[1][0] - 'a'][s[1][len[1] - 1] - 'a'] = len[1];
  int i = 1;
  for (long long t = 2; t <= n; t++) {
    i ^= 1;
    for (long long j = 0; j <= 25; j++)
      for (long long k = 0; k <= 25; k++) f[i][j][k] = f[1 ^ i][j][k];
    for (long long j = 0; j <= 25; j++)
      if (f[i][j][s[t][0] - 'a'])
        f[i][j][s[t][len[t] - 1] - 'a'] = max(f[i][j][s[t][len[t] - 1] - 'a'],
                                              f[i][j][s[t][0] - 'a'] + len[t]);
    if (f[i][s[t][0] - 'a'][s[t][len[t] - 1] - 'a'] == 0)
      f[i][s[t][0] - 'a'][s[t][len[t] - 1] - 'a'] = len[t];
    else
      f[i][s[t][0] - 'a'][s[t][len[t] - 1] - 'a'] =
          max(f[i][s[t][0] - 'a'][s[t][len[t] - 1] - 'a'], len[t]);
  }
  int ans = 0;
  for (long long i = 0; i <= 25; i++) ans = max(ans, f[n % 2][i][i]);
  cout << ans << endl;
  return 0;
}
