#include <bits/stdc++.h>
using namespace std;
struct s {
  int begin, end, len;
} a[500005];
char str[15];
int dp[27][27];
int main() {
  int n;
  while (~scanf("%d", &n)) {
    for (int i = 0; i < n; i++) {
      scanf("%s", str);
      a[i].len = strlen(str);
      a[i].begin = str[0] - 'a' + 1;
      a[i].end = str[a[i].len - 1] - 'a' + 1;
    }
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < n; i++) {
      for (int j = 1; j <= 26; j++) {
        if (dp[j][a[i].begin] != 0)
          dp[j][a[i].end] = max(dp[j][a[i].begin] + a[i].len, dp[j][a[i].end]);
      }
      dp[a[i].begin][a[i].end] = max(dp[a[i].begin][a[i].end], a[i].len);
    }
    int ma = 0;
    for (int i = 1; i <= 26; i++) {
      ma = max(ma, dp[i][i]);
    }
    printf("%d\n", ma);
  }
  return 0;
}
