#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:134217728")
using namespace std;
char buf[1 << 4];
int n;
int dp[26][26];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < 26; ++i)
    for (int j = 0; j < 26; ++j) dp[i][j] = i == j ? 0 : -(int)1e9;
  for (int i = 0; i < n; ++i) {
    scanf("%s", buf);
    int len = strlen(buf);
    int L = buf[0] - 'a';
    int R = buf[len - 1] - 'a';
    for (int j = 0; j < 26; ++j)
      if (dp[j][L] != -1) dp[j][R] = max(dp[j][L] + len, dp[j][R]);
  }
  int res = 0;
  for (int i = 0; i < 26; ++i) res = max(res, dp[i][i]);
  printf("%d\n", res);
  return 0;
}
