#include <bits/stdc++.h>
int max(int a, int b) { return (a < b) ? b : a; }
int main(void) {
  int mat[26][26], n, i, j, len, first, last, ans;
  char buff[20];
  ans = 0;
  memset(mat, 0, sizeof(mat));
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%s", &buff);
    len = strlen(buff);
    first = buff[0] - 97;
    last = buff[len - 1] - 97;
    for (j = 0; j < 26; j++) {
      if (mat[j][first] != 0) {
        mat[j][last] = max(mat[j][first] + len, mat[j][last]);
      }
    }
    mat[first][last] = max(mat[first][last], len);
  }
  for (i = 0; i < 26; i++) {
    ans = max(ans, mat[i][i]);
  }
  printf("%d", ans);
  return 0;
}
