#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 5;
char s[N];
int dp[30][30];
int main() {
  int n;
  scanf("%d", &n);
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < n; ++i) {
    scanf("%s", s);
    int len = strlen(s);
    int head = s[0] - 'a';
    int tail = s[len - 1] - 'a';
    for (int j = 0; j < 26; ++j) {
      if (dp[j][head]) dp[j][tail] = max(dp[j][tail], dp[j][head] + len);
    }
    dp[head][tail] = max(len, dp[head][tail]);
  }
  int ans = 0;
  for (int i = 0; i < 26; ++i) ans = max(ans, dp[i][i]);
  printf("%d\n", ans);
  return 0;
}
