#include <bits/stdc++.h>
using namespace std;
int dp[30][30];
int N;
char s[11];
int main() {
  memset(dp, -1, sizeof dp);
  cin >> N;
  for (int i = 0; i < N; i++) {
    scanf("%s", s);
    int k = strlen(s);
    int a = s[0] - 'a';
    int b = s[k - 1] - 'a';
    for (int j = 0; j < 26; j++) {
      if (dp[j][a] == -1) continue;
      dp[j][b] = max(dp[j][b], dp[j][a] + k);
    }
    dp[a][b] = max(dp[a][b], k);
  }
  int ret = 0;
  for (int i = 0; i < 26; i++) {
    ret = max(ret, dp[i][i]);
  }
  cout << ret << endl;
}
