#include <bits/stdc++.h>
using namespace std;
int f[30][30], ans = 0;
bool b[30][30];
int main() {
  int n;
  scanf("%d", &n);
  memset(f, 0, sizeof(f));
  memset(b, 0, sizeof(f));
  while (n--) {
    char s[40];
    scanf("%s", s + 1);
    int l = strlen(s + 1);
    for (int i = 0; i < 26; i++) {
      if (!b[i][s[1] - 'a'] && s[1] - 'a' != i) continue;
      b[i][s[1] - 'a'] = b[i][s[l] - 'a'] = true;
      f[i][s[l] - 'a'] = max(f[i][s[l] - 'a'], l + f[i][s[1] - 'a']);
    }
  }
  for (int i = 0; i < 26; i++) ans = max(ans, f[i][i]);
  printf("%d\n", ans);
  return 0;
}
