#include <bits/stdc++.h>
using namespace std;
int dp[30][30], t;
char str[500010][20];
int main() {
  while (~scanf("%d", &t)) {
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < t; i++) scanf("%s", str[i]);
    for (int i = 0; i < t; i++) {
      int len = strlen(str[i]);
      int _begin = str[i][0] - 'a';
      int _end = str[i][len - 1] - 'a';
      for (int j = 0; j < 26; j++) {
        if (dp[j][_begin]) dp[j][_end] = max(dp[j][_end], dp[j][_begin] + len);
      }
      dp[_begin][_end] = max(len, dp[_begin][_end]);
    }
    int ans = -1;
    for (int i = 0; i < 26; i++) ans = max(ans, dp[i][i]);
    printf("%d\n", ans);
  }
}
