#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  char str[12];
  int f[28][28] = {0};
  scanf("%d", &n);
  while (n--) {
    scanf("%s", str);
    int len = strlen(str);
    int l = str[0] - 'a';
    int r = str[len - 1] - 'a';
    for (int i = 0; i < 26; i++) {
      if (f[i][l]) {
        f[i][r] = max(f[i][r], f[i][l] + len);
      }
    }
    f[l][r] = max(f[l][r], len);
  }
  n = 0;
  for (int i = 0; i < 26; i++) {
    n = max(n, f[i][i]);
  }
  printf("%d\n", n);
  return 0;
}
