#include <bits/stdc++.h>
int n, len, i, f[200][200];
char s[20], a, b;
int max(int a, int b) {
  if (a > b)
    return a;
  else
    return b;
}
int main() {
  scanf("%d", &n);
  memset(f, 0, sizeof(f));
  while (n--) {
    scanf("%s", &s);
    len = strlen(s);
    a = s[0];
    b = s[len - 1];
    for (i = 'a'; i <= 'z'; i++) {
      if (f[i][a] == 0) continue;
      f[i][b] = max(f[i][b], f[i][a] + len);
    }
    f[a][b] = max(f[a][b], len);
  }
  n = 0;
  for (i = 'a'; i <= 'z'; i++) {
    n = max(n, f[i][i]);
  }
  printf("%d\n", n);
  return 0;
}
