#include <bits/stdc++.h>
using namespace std;
int f[26][26];
char str[15];
int main() {
  int n;
  cin >> n;
  memset(f, 0x9f, sizeof f);
  for (int i = 0; i < n; i++) {
    scanf("%s", str);
    int len = strlen(str);
    int j = str[0] - 'a', k = str[len - 1] - 'a';
    for (int l = 0; l < 26; l++) {
      f[l][k] = max(f[l][k], f[l][j] + len);
    }
    f[j][k] = max(f[j][k], len);
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) {
    if (f[i][i] > ans) ans = f[i][i];
  }
  cout << ans << endl;
  return 0;
}
