#include <bits/stdc++.h>
using namespace std;
int dp[26][26];
char s[15];
int main() {
  ios_base::sync_with_stdio(0);
  int N;
  int pre = 0;
  int next = 1;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%s", s);
    int len = strlen(s);
    int start = s[0] - 'a';
    int end = s[len - 1] - 'a';
    for (int j = 0; j < 26; j++) {
      if (dp[j][start]) dp[j][end] = max(dp[j][end], dp[j][start] + len);
    }
    dp[start][end] = max(dp[start][end], len);
  }
  int maxx = 0;
  for (int i = 0; i < 26; i++) maxx = max(maxx, dp[i][i]);
  cout << maxx << endl;
  return 0;
}
