#include <bits/stdc++.h>
using namespace std;
int main() {
  int arr[26][26];
  char inp[12];
  int len, a, b, n;
  for (int i = 0; i <= 26 - 1; i++) {
    for (int j = 0; j <= 26 - 1; j++) {
      arr[i][j] = 0;
    }
  }
  scanf("%d", &n);
  for (int i = 0; i <= n - 1; i++) {
    scanf("%s", inp);
    len = strlen(inp);
    a = inp[0] - 97;
    b = inp[len - 1] - 97;
    arr[a][b] = max(arr[a][b], arr[a][a] + len);
    for (int y = 0; y <= 26 - 1; y++) {
      if (y == a) continue;
      if (arr[y][a] > 0) arr[y][b] = max(arr[y][b], arr[y][a] + len);
    }
  }
  int ans = 0;
  for (int i = 0; i <= 26 - 1; i++) ans = max(ans, arr[i][i]);
  printf("%d\n", ans);
  return 0;
}
