#include <bits/stdc++.h>
int dp[26][26], n, ans;
char s[15];
int main() {
  int i, len, x, y;
  memset(dp, 0, sizeof(dp));
  scanf("%d", &n);
  while (n--) {
    scanf("%s", s);
    len = strlen(s);
    x = s[0] - 'a';
    y = s[len - 1] - 'a';
    for (i = 0; i < 26; i++)
      if (dp[i][x] && dp[i][y] < dp[i][x] + len) dp[i][y] = dp[i][x] + len;
    if (len > dp[x][y]) dp[x][y] = len;
  }
  ans = 0;
  for (i = 0; i < 26; i++)
    if (dp[i][i] > ans) ans = dp[i][i];
  printf("%d\n", ans);
  return 0;
}
