#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int dp[30][30], n;
char g[110];
int main() {
  while (~scanf("%d", &n)) {
    memset(dp, 0, sizeof dp);
    while (n--) {
      scanf("%s", g);
      int l = strlen(g);
      int a = g[0] - 'a', b = g[l - 1] - 'a';
      for (int(i) = 0; (i) < (26); (i)++)
        if (dp[i][a] && dp[i][b] < dp[i][a] + l) dp[i][b] = dp[i][a] + l;
      if (dp[a][b] < l) dp[a][b] = l;
    }
    int ans = -1;
    for (int(i) = 0; (i) < (26); (i)++) ans = max(ans, dp[i][i]);
    printf("%d\n", ans);
  }
  return 0;
}
